当前位置:网站首页>E - Integer Sequence Fair
E - Integer Sequence Fair
2022-08-01 22:42:00 【秦小咩】
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 500500 points
Problem Statement
Integer Sequence Exhibition is taking place, where integer sequences are gathered in one place and evaluated. Here, every integer sequence of length NN consisting of integers between 11 and KK (inclusive) is evaluated and given an integer score between 11 and MM (inclusive).
Print the number, modulo 998244353998244353, of ways to give each of the evaluated sequences a score between 11 and MM.
Here, two ways are said to be different when there is an evaluated sequence A = (A_1, A_2, \ldots, A_N)A=(A1,A2,…,AN) that is given different scores by the two ways.
Constraints
- 1 \leq N, K, M \leq 10^{18}1≤N,K,M≤1018
- NN, KK, and MM are integers.
Input
Input is given from Standard Input in the following format:
NN KK MM
Output
Print the number, modulo 998244353998244353, of ways to give each of the evaluated sequences a score between 11 and MM.
Sample Input 1 Copy
Copy
2 2 2
Sample Output 1 Copy
Copy
16
Four sequences are evaluated: (1, 1)(1,1), (1, 2)(1,2), (2, 1)(2,1), and (2, 2)(2,2). There are 1616 ways to give each of these sequences a score between 11 and 22, as follows.
- Give 11 to (1, 1)(1,1), 11 to (1, 2)(1,2), 11 to (2, 1)(2,1), and 11 to (2, 2)(2,2)
- Give 11 to (1, 1)(1,1), 11 to (1, 2)(1,2), 11 to (2, 1)(2,1), and 22 to (2, 2)(2,2)
- Give 11 to (1, 1)(1,1), 11 to (1, 2)(1,2), 22 to (2, 1)(2,1), and 11 to (2, 2)(2,2)
- Give 11 to (1, 1)(1,1), 11 to (1, 2)(1,2), 22 to (2, 1)(2,1), and 22 to (2, 2)(2,2)
- \cdots⋯
- Give 22 to (1, 1)(1,1), 22 to (1, 2)(1,2), 22 to (2, 1)(2,1), and 22 to (2, 2)(2,2)
Thus, we print 1616.
Sample Input 2 Copy
Copy
3 14 15926535
# include<iostream>
# include<iomanip>
# include<algorithm>
# include<map>
# include<vector>
# include<set>
# include<cstring>
# pragma optimize(2)
# define mod1 998244353
# define mod2 998244352
using namespace std;
typedef long long int ll;
ll qp2(ll base, ll pow)
{
ll ans=1;
while(pow)
{
if(pow&1)
ans=ans*base%mod2;
pow>>=1;
base=base*base%mod2;
}
return ans;
}
ll qp1(ll base, ll pow)
{
ll ans=1;
while(pow)
{
if(pow&1)
ans=ans*base%mod1;
pow>>=1;
base=base*base%mod1;
}
return ans;
}
int main ()
{
ll n,k,m;
cin>>n>>k>>m;
if(m%998244353==0)
{
cout<<0;
return 0;
}
else
{
ll now=qp2(k%(mod2),n);
ll ans=qp1(m%(mod1),now);
cout<<ans<<'\n';
}
return 0;
}
Sample Output 2 Copy
Copy
109718301
Be sure to print the count modulo 998244353998244353.
=========================================================================
费马小定理的应用
正整数 n , 当模数p是质数,且 gcd(n,p)==1时,n^(p-1)=1 (mod p)
本题答案显然是
,显然会想到快速幂,但我们长做的快速幂,指数部分是无法进行取模操作的,而本题的指数一旦不取模,会立刻炸掉,所以考虑对指数进行一些操作
如果m与p不互质,又因为p是质数,故m一定是p的倍数,此时已知答案为0
如果m与p互质,那么,将k^n拆分成 x*(p-1) + mod ,左半部分答案是1,右半部分答案直接用快速幂就可以直接解决。
边栏推荐
- visual studio code multiple editing
- No more rolls!After joining ByteDance for a week, he ran decisively.
- long investment career
- Getting Started Database Days4
- Yizhou Financial Analysis | The intelligent transformation of bank ATM machines is accelerated; the new Internet loan regulations bring challenges
- excel remove all carriage return from a cell
- 力扣第 304 场周赛复盘
- Postman batch test interface detailed tutorial
- feel so stupid
- excel edit a cell without double clicking
猜你喜欢

No more rolls!After joining ByteDance for a week, he ran decisively.

03. GO language variable definition, function

y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)

小程序毕设作品之微信体育馆预约小程序毕业设计成品(2)小程序功能

(Translation) How the contrasting color of the button guides the user's actions

blender3.2.1 unit setting

使用Jenkins做持续集成,这个知识点必须要掌握

xctf attack and defense world web master advanced area webshell

【SeaTunnel】从一个数据集成组件演化成企业级的服务

feel so stupid
随机推荐
系统可用性:SRE口中的3个9,4个9...到底是个什么东西?
如何使用pywinauto和pyautogui将动漫小姐姐链接请回家
联邦学习在金融领域的发展和应用
SQL Server (design database--stored procedure--trigger)
Create virtual environments with virtualenv and Virtualenvwrapper virtual environment management tools
y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)
毫秒级!千万人脸库快速比对,上亿商品图片检索,背后的极速检索用了什么神器?
[Mobile Web] Mobile terminal adaptation
基于 OData 模型和 JSON 模型的 SAP UI5 表格控件行项目的添加和删除实现
使用Jenkins做持续集成,这个知识点必须要掌握
编曲软件FL studio20.8中文版功能和作用
PHP算法之有效的括号
The must-have "fishing artifact" for programmers is here!
PHP算法之最接近的三数之和
Go 微服务开发框架DMicro的设计思路
Today's sleep quality record 74 points
【好书推荐】第一本无人驾驶技术书
Lecture 3: Several common table field data types in MySQL database
深度学习Course2第二周Optimization Algorithms习题整理
leetcode 204. Count Primes 计数质数 (Easy)