当前位置:网站首页>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,右半部分答案直接用快速幂就可以直接解决。
边栏推荐
- xctf攻防世界 Web高手进阶区 webshell
- 1391D. 505 状压dp
- excel edit a cell without double clicking
- 力扣第 304 场周赛复盘
- excel edit a cell without double clicking
- Lecture 3: Several common table field data types in MySQL database
- [机缘参悟-58]:《素书》-5-奉行仁义[遵义章第五]
- Wechat Gymnasium Reservation Mini Program Graduation Design Finished Work Mini Program Graduation Design Finished Product (2) Mini Program Function
- 【SeaTunnel】从一个数据集成组件演化成企业级的服务
- 深度学习Course2第一周Practical aspects of Deep Learning习题整理
猜你喜欢
Analysis of the development trend of game metaverse
npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)
[Niu Ke brush questions-SQL big factory interview questions] NO4. Travel scene (a taxi)
User Experience | How to Measure User Experience?
小程序中的多表联合查询
隔离和降级
美赞臣EDI 940仓库装运订单详解
一种灵活的智能合约协作方式
03、GO语言变量定义、函数
xctf攻防世界 Web高手进阶区 web2
随机推荐
PAM 回文自动机
Prufer序列
JS prototype hasOwnProperty in 加方法 原型终点 继承 重写父类方法
将vim与系统剪贴板的交互使用
关于ETL的两种架构(ETL架构和ELT架构)
Quarantine and downgrade
字符串——Trie
Graph Theory - Strongly Connected Component Condensation + Topological Sort
y84.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十五)
图论——强连通分量缩点+拓扑排序
[ASM] Bytecode Operation MethodWriter
From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program
Mini Program Graduation Works WeChat Food Recipe Mini Program Graduation Design Finished Product (8) Graduation Design Thesis Template
Delicious this year
文件查询匹配神器 【glob.js】 实用教程
leetcode 204. Count Primes 计数质数 (Easy)
npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)
Three, mysql storage engine - building database and table operation
编曲软件FL studio20.8中文版功能和作用
数据增强--学习笔记(图像类,cnn)