思路分析:
以知 。
可以转化为,。
所以,对于每一个 ,我们需要找到 使得以上等式成立。
由于 是一个质数,我们可以利用模运算的性质,。
因为 的周期是 , 的周期是 ,所以最大周期为 ,大于 ,所以直接遍历就行了。
代码步骤如下。
-
遍历 从 到 ,计算 ,用一个桶数组 , 的第 加一。同时,可以记录每个 的 的值,以便后续统计,注意 的值都要取余。
-
然后遍历 从 到 ,统计有多少个数字符合题意。
代码:
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL f(LL a,LL b){
LL sum=1;
while(b){
if(b&1){
sum=(sum*a)%6421;
}
a=a*a%6421;
b/=2;
}
return sum;
}
LL a[2000001];
int main(){
LL sum=0;
for(LL i=1;i<=20240601;i++){
if(i%6421==0){
a[0]++;
}
else {
a[f(i%6421,i%6420)]++;
}
}
for(LL i=0;i<6421;i++){
if(i<(6421-i)%6421){
sum+=a[i]*a[(6421-i)%6421];
}
else if (i==(6421-i)%6421){
sum+=a[i]*(a[i]-1)/2;
}
}
cout<<sum<<endl;
return 0;
}输出答案代码。
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"51349141107"<<endl;
return 0;
}打完后得到答案为 。