QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471510#6704. Happy Equationchenxinyang2006AC ✓1ms3856kbC++201.4kb2024-07-10 21:41:122024-07-10 21:41:14

Judging History

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

  • [2024-07-10 21:41:14]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3856kb
  • [2024-07-10 21:41:12]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
	if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
	if(x > y) x = y;
}

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}


/*ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;	
	}
	return ans;
}*/
int T,n,p;

uint power(uint pp,int K){
	uint ans = 1;
	while(K){
		if(K & 1) ans *= pp;
		pp *= pp;
		K /= 2;
	}
	return ans & ((1 << p) - 1);
}

void solve(){
	scanf("%d%d",&n,&p);
	if(n & 1){
		printf("1\n");
		return;
	}
	int answer = 0;
	uint cur = 1,temp;
	rep(k,1,p - 1){
		cur *= n;
		cur &= (1 << p) - 1;
		temp = power(k,n);
		if(!temp) answer--;
		if(temp == cur) answer++;
	}
	answer += 1 << (p - (p + n - 1) / n);
	printf("%d\n",answer);
}

int main(){
	scanf("%d",&T);
	while(T--) solve();
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
6 12
8 16

output:

1023
16383

result:

ok 2 number(s): "1023 16383"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3856kb

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