QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#612083#6704. Happy Equationkevinyang#AC ✓4ms3660kbC++141.1kb2024-10-05 04:46:112024-10-05 04:46:11

Judging History

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

  • [2024-10-05 04:46:11]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3660kb
  • [2024-10-05 04:46:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int mod = (int)1e9+7;//change this if needed
int modpow(int x, int y) {
	return !y?1:((y % 2 ? x : 1) * modpow((x * x) % mod, y / 2)) % mod;
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin >> t;
	while(t--){
		int a,p;
		cin >> a >> p;
		mod = 1<<p;
		if(a%2 == 1){
			cout << "1\n";
			continue;
		}
		if(a<=p){
			int k = (p+a-1)/a;
			int v = 1<<(p-k);
			for(int j = 1; j<=p; j++){
				if(j%(1<<k) == 0){
					if(modpow(a,j) != modpow(j,a)){
						v--;
					}
				}
				else{
					if(modpow(a,j) == modpow(j,a)){
						v++;
					}
				}
			}
			cout << v << '\n';
		}
		else{
			int v = 1<<(p-1);
			for(int j = 2; j<=p; j+=2){
				if(modpow(a,j) != modpow(j,a)){
					v--;
				}
			}
			for(int j = 1; j<=p; j+=2){
				if(modpow(a,j) == modpow(j,a)){
					v++;
				}
			}
			cout << v << '\n';
		}
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

input:

2
6 12
8 16

output:

1023
16383

result:

ok 2 number(s): "1023 16383"

Test #2:

score: 0
Accepted
time: 4ms
memory: 3660kb

input:

1000
959668315 17
173599849 18
452866086 16
984874375 15
346061855 21
440851881 22
224960642 16
176079916 16
656766412 21
283466925 25
20353211 27
691728649 20
772055116 17
459468637 21
206618043 15
987058694 25
621275781 22
787193761 15
812760680 25
993799948 25
126264161 18
897813346 16
762713004 ...

output:

1
1
32761
1
1
1
32761
32765
1048571
1
1
1
65532
1
1
16777204
1
1
16777212
16777210
1
32761
16777210
1
1
33554420
32761
1
16777204
1
2097142
8388603
262142
1
1
16777204
4194299
134217722
1
1
8388597
1
1
1
32761
1
1
1
268435449
524279
1
1
67108860
1
1
1
4194293
1048571
67108851
1
1
1
131064
1
1
167772...

result:

ok 1000 numbers