暴力枚举
#include <bits/stdc++.h>
using namespace std;
int vis[65];
int f(int x, int k, int a){
int res = 0, tmp = x;
for(int i = 2; i <= 5; i++) tmp = tmp*x%65;
res = (res+13*tmp)%65;
for(int i = 6; i <= 13; i++) tmp = tmp*x%65;
res = (res+5*tmp)%65;
res = (res+a%65*k%65*x%65)%65;
return res;
}
int main(){
int k;
while(scanf("%d", &k) == 1){
memset(vis, 0, sizeof vis);
k %= 65;
for(int x = 1; x <= 64; x++){
for(int a = 0; a <= 64; a++){
if(!vis[a] && f(x, k, a)%65 != 0)
vis[a] = 1;
}
}
for(int i = 0; i <= 64; i++){
if(vis[i] == 0){
printf("%d\n", i);
break;
}
if(i == 64) printf("no\n");
}
}
return 0;
}
推导法
#include <bits/stdc++.h>
using namespace std;
int main(){
int k;
while(scanf("%d", &k) == 1){
k %= 65;
for(int a = 0; a <= 64; a++){
// f(1)=18+a*k
// (f(x+1)-f(x))%65 == 0,即任意x时f(x)同余
if((18+a*k)%65 == 0){
printf("%d\n", a);
break;
}
if(a == 64) printf("no\n");
}
}
return 0;
}