ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213784 | #2157. 数列 | cheatme | 100 | 549ms | 33272kb | C++11 | 4.5kb | 2024-11-13 19:34:51 | 2024-11-13 23:02:20 |
answer
#include <bits/stdc++.h>
#define int long long
#define file(x) {freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);}
namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define io Fastio::cin
#define IO Fastio::cout
int T = 1;
const int maxn = 2000005;
int mp[maxn], pr[maxn / 10], cnt[maxn], n, mod;
int qpow(int a,int b){
int ans = 1;
while(b){
if(b & 1) {
ans = ans * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return ans;
}
void solve(){
Fastio::cin >> n >> mod;
int pn = 0;
for(int i = 2; i <= 2 * n; i++){
if(!mp[i])pr[++pn]=i,mp[i]=i;
for(int j = 1; j <= pn && i * pr[j] <= 2 * n; j++){
mp[i * pr[j]] = pr[j];
if(i % pr[j] == 0)break;
}
}
for(int i = 1; i <= n; i++)cnt[i] = -1;
for(int i = n + 2; i <= 2 * n; i++)cnt[i] = 1;
for(int i = 2 * n; i > 1; i--)
if(mp[i] < i)cnt[mp[i]] += cnt[i],cnt[i / mp[i]] += cnt[i];
int ans = 1;
for(int i = 2; i <= 2 * n; i++)
if(mp[i] == i)ans = ans * qpow(i, cnt[i]) % mod;
Fastio::cout << ans << '\n';
}
int32_t main(){
// file("A");
// Fastio::cin >> T;
while(T--){
solve();
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 1160kb
input:
921 998054347
output:
345389219
result:
ok single line: '345389219'
Test #2:
score: 5
Accepted
time: 0ms
memory: 1160kb
input:
926 998064329
output:
458756691
result:
ok single line: '458756691'
Test #3:
score: 5
Accepted
time: 0ms
memory: 1164kb
input:
1000 998074327
output:
457273797
result:
ok single line: '457273797'
Test #4:
score: 5
Accepted
time: 0ms
memory: 1160kb
input:
952 998084303
output:
329700115
result:
ok single line: '329700115'
Test #5:
score: 5
Accepted
time: 0ms
memory: 1164kb
input:
989 998094347
output:
94788253
result:
ok single line: '94788253'
Test #6:
score: 5
Accepted
time: 0ms
memory: 1164kb
input:
902 998104313
output:
911969455
result:
ok single line: '911969455'
Test #7:
score: 5
Accepted
time: 0ms
memory: 1160kb
input:
914 998114333
output:
827812986
result:
ok single line: '827812986'
Test #8:
score: 5
Accepted
time: 0ms
memory: 1160kb
input:
986 998124313
output:
169699253
result:
ok single line: '169699253'
Test #9:
score: 5
Accepted
time: 0ms
memory: 1160kb
input:
947 998134339
output:
761932751
result:
ok single line: '761932751'
Test #10:
score: 5
Accepted
time: 0ms
memory: 1164kb
input:
934 998144339
output:
42889072
result:
ok single line: '42889072'
Test #11:
score: 5
Accepted
time: 52ms
memory: 33272kb
input:
991572 998154343
output:
277089318
result:
ok single line: '277089318'
Test #12:
score: 5
Accepted
time: 52ms
memory: 31372kb
input:
932800 998164337
output:
945072504
result:
ok single line: '945072504'
Test #13:
score: 5
Accepted
time: 50ms
memory: 30432kb
input:
903603 998174341
output:
29916736
result:
ok single line: '29916736'
Test #14:
score: 5
Accepted
time: 58ms
memory: 32208kb
input:
958646 998184331
output:
802903490
result:
ok single line: '802903490'
Test #15:
score: 5
Accepted
time: 59ms
memory: 32992kb
input:
983016 998194349
output:
802900579
result:
ok single line: '802900579'
Test #16:
score: 5
Accepted
time: 47ms
memory: 31032kb
input:
922347 998204353
output:
228575331
result:
ok single line: '228575331'
Test #17:
score: 5
Accepted
time: 61ms
memory: 32768kb
input:
976053 998214317
output:
982618317
result:
ok single line: '982618317'
Test #18:
score: 5
Accepted
time: 55ms
memory: 32164kb
input:
957300 998224351
output:
514549818
result:
ok single line: '514549818'
Test #19:
score: 5
Accepted
time: 53ms
memory: 31016kb
input:
921760 998234353
output:
470386410
result:
ok single line: '470386410'
Test #20:
score: 5
Accepted
time: 62ms
memory: 30732kb
input:
912948 998244353
output:
129235345
result:
ok single line: '129235345'