Code:
#include <iostream> #include <cstring> #include <algorithm> using namespace std; #define int long long const int N = 1e5 + 10, M = 1e5; int c; int qmul(int a,int p,int mod){ int res=0; while(p){ if(p&1)res=(res+a)%mod; a=(a+a)%mod; p>>=1; } return res; }//慢速乘,用于解决快速幂中的两个1e10相乘爆ll问题 int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } int qmi(int a, int p, int mod) { int res = 1; while (p) { if (p & 1)res = qmul(res,a,mod)%mod; a = qmul(a,a,mod)%mod; p >>= 1; } return res; } bool check(int x) { if (qmi(10, x, c) == 1)return 1; return 0; } signed main() { int L; int id = 0; while (cin >> L, L) { printf("Case %lld: ", ++id); c = 9 * L / gcd(L, 8); if (gcd(c, 10) != 1)cout << 0 << endl; else { int phi = c; int tc = c; for (int i = 2; i <= M; i++) { int cnt = 0; while (tc%i == 0) { cnt++; tc /= i; } if(cnt)phi = phi * (i - 1) / i; }//求欧拉函数 if(tc!=1)phi = phi /tc *(tc-1);//先除后乘,不然又爆ll了... int res = phi; for (int i = 1; i*i<=phi; i++) { if (phi%i == 0 ){ if(check(i))res=min(res,i); if(check(phi/i))res=min(res,phi/i); //求约数 } } cout<<res<<endl; } } }
有诸多的坑
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】