QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#430116 | #4867. So Easy! | Nevll | TL | 0ms | 0kb | C++14 | 630b | 2024-06-03 14:36:57 | 2024-06-03 14:37:00 |
answer
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
# define pii pair<int, int>
using namespace std;
ll MOD;
ll fast(ll a, ll b) {
if(b == 0) return 1ll % MOD;
if(b == 1) return a % MOD;
ll K = fast(a, b / 2ll);
K *= K;
K %= MOD;
if(b&1) {
K *= (a % MOD);
K %= MOD;
}
return K;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int a, b, n;
while(cin>>a>>b>>n>>MOD) {
ll ans = 0ll;
for(int i=n;i>=0;i-=2) {
ans += (fast(a, i) * fast(b, (n - i) / 2))%MOD;
ans %= MOD;
}
ans *= 2ll;
ans %= MOD;
cout<<ans<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 3 1 2012 2 3 2 2012 2 2 1 2012 31603 998691525 860250282 20381 4062 16491843 2741468 17921 26061 679145378 8235021 22991 16225 263237214 865378598 7182 18902 357253267 137732528 3407 25414 645847050 674769818 7114 6903 47648125 254957745 1556 16577 274779382 158233677 1099 939 880815 990631973 610...