QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#304638 | #7881. Computational Complexity | ucup-team134 | WA | 0ms | 4016kb | C++14 | 2.6kb | 2024-01-13 22:22:41 | 2024-01-13 22:22:42 |
Judging History
answer
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
using namespace std;
using u128=__uint128_t;
typedef pair<int,int> pii;
ll mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}
const int maxn=6e6+10;
const int maxalp=10;
unordered_map<ll,ll>gm,fm;
ll f0,g0;
ll g(ll n);
ll f(ll n){
///printf("%lld AAA\n",n);
if(fm.find(n)!=fm.end())return fm[n];
if(n==0)return f0;
ll ret=g(n/2);
ret+=g(n/3);
if(ret>=mod)ret-=mod;
ret+=g(n/5);
if(ret>=mod)ret-=mod;
ret+=g(n/7);
if(ret>=mod)ret-=mod;
ret=max(ret,n);
if(ret>=mod)ret%=mod;
fm[n]=ret;
return ret;
}
ll g(ll n){
if(gm.find(n)!=gm.end())return gm[n];
if(n==0)return g0;
ll ret=f(n/2);
ret+=f(n/3);
if(ret>=mod)ret-=mod;
ret+=f(n/5);
if(ret>=mod)ret-=mod;
ret+=f(n/4);
if(ret>=mod)ret-=mod;
ret=max(ret,n);
if(ret>=mod)ret%=mod;
gm[n]=ret;
return ret;
}
int main(){
///freopen("test.txt","r",stdin);
ll n=1e15;
/*double pp=0;
pp+=1.0/2+1.0/3+1.0/5+1.0/4;
cout<<fixed<<setprecision(6)<<pp<<endl;
using int128=__int128_t;
int128 pw2=1;
int rez=0;
for(int i=1;i<=50;i++){
int128 pw3=1;
for(int j=1;j<=40;j++){
int128 pw5=1;
for(int k=1;k<=40;k++){
int128 pw7=1;
for(int p=1;p<=40;p++){
int128 pom=1;
pom=pw2*pw3;
if(pom<=n){
pom=pom*pw5;
if(pom<=n){
pom=pom*pw7;
if(pom<=n)rez++;
}
}
pw7*=7;
if(pw7>n)break;
}
pw5*=5;
if(pw5>n)break;
}
pw3*=3;
if(pw3>n)break;
}
pw2*=2;
if(pw2>n)break;
}
printf("%d\n",rez);*/
int t;
scanf("%d %d %d %lld",&f0,&g0,&t,&mod);
f0%=mod;
g0%=mod;
while(t--){
ll m;
scanf("%lld",&m);
printf("%lld %lld\n",f(m),g(m));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
input:
1958 920 10 100000000000 0 1 2 3 10 100 200 1000 19580920 20232023
output:
1958 920 3680 7832 10592 9554 17504 11276 50294 64826 784112 893714 1894550 1905470 12057866 12979424 71481494756 48626708512 28127864908 7251681354
result:
ok 20 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
0 0 10 100000000000 0 1 2 3 4 10 20 30 40 100
output:
0 0 1 1 2 2 3 3 4 4 11 12 25 26 41 41 55 58 162 172
result:
ok 20 numbers
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 4016kb
input:
2023 2023 10 2023 0 1 2 3 4 5 6 7 8 9
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 7 7 7 8 9 9 10
result:
wrong answer 3rd numbers differ - expected: '0', found: '1'