QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#430116#4867. So Easy!NevllTL 0ms0kbC++14630b2024-06-03 14:36:572024-06-03 14:37:00

Judging History

你现在查看的是最新测评结果

  • [2024-06-03 14:37:00]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-06-03 14:36:57]
  • 提交

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";
	}
}

详细

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...

output:


result: