3 条题解

  • 0
    @ 2024-3-27 16:33:57
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
     
    LL n;
     
    LL Pow(LL a, LL b, LL mod)
    {
        LL res = 1;
        while (b)
        {
            if (b&1)
                res = (res*a)%mod;
            a = (a*a)%mod;
            b >>= 1;
        }
        return res;
    }
     
    LL Euler(LL x)
    {
        LL res = x;
        for (int i = 2;i <= x;i++)
        {
            if (x%i == 0)
            {
                while (x % i == 0)
                    x /= i;
                res = res/i*(i - 1);
            }
        }
        if (x > 1)
            res = res/x*(x-1);
        return res;
    }
     
    LL Solve(int cnt, LL mod)
    {
        LL res = 1e18;
        for (LL i = 1;i*i <= cnt;i++)
        {
            if (cnt%i == 0)
            {
    //            cout << i << endl;
                if (Pow(10, i, mod) == 1)
                    res = min(res, i);
                if (Pow(10, cnt/i, mod) == 1)
                    res = min(res, cnt/i);
            }
        }
        if (res == 1e18)
            return 0;
        return res;
    }
     
    int main()
    {
        int cnt = 0;
        while (~scanf("%lld", &n) && n)
        {
            LL eul = Euler((9LL*n)/__gcd(8LL, n*9));
    //        cout << eul << endl;
            LL res = Solve(eul, (9LL*n)/__gcd(8LL, n*9));
            printf("Case %d: %lld\n", ++cnt, res);
        }
     
        return 0;
    }
    
    • 0
      @ 2023-9-29 14:00:07

      #include<iostream> #include<algorithm> #include<cstring>

      using namespace std; typedef long long ll;

      ll gcd(ll a,ll b) // 非常基础的最大公约数模板 { return b?gcd(b,a%b):a; }

      ll get_euler(ll n) // 试除法 求 欧拉函数值模板 { ll s=n; for(ll i=2;i<=n/i;i++) { if(n%i0) { while(n%i0) n/=i; s = s / i * (i - 1); } } if(n>1) s=s/n*(n-1); return s; } ll quick_mul(ll a,ll b,ll c) // 龟速乘模板 { ll s=0;//注意初值为0,因为是累加。 while(b) { if(b&1) s = (s + a)%c; a = (a+a)%c; b/=2; } return s; } ll quick_mi(ll a,ll b,ll c) //快速幂模板 { ll s=1; while(b) { if(b&1) s = quick_mul(s,a,c); a=quick_mul(a,a,c); b/=2; } return s; } int main(void) { ll n; int T = 1; while(cin>>n,n) { ll mini = 1e18;

      ll d=gcd(n,8),a=9*n/d,phi=get_euler(a);
          // 分别对应的就是解析中的 d、A、φ(A)
      
       	if(a%2==0||a%5==0) mini=0; // 如果不是互质,根据定理直接无解。
       	else
       	for(ll i=1;i<=phi/i;i++) // 枚举约数进行判断。
       	    if(phi%i==0) // 因为因数都是一对一对的,找到其中一个就够了,
       	    {
       		    if(quick_mi(10,i,a)==1) mini=min(mini,i); //判断 10^i % a 等不等于1,并且更新mini值。
       		    if(quick_mi(10,phi/i,a)==1) mini=min(mini,phi/i);//同上
      	    }
       	printf("Case %d: %lld\n", T ++ , mini);
       	
        } 
      return 0;
      
      • [ ] 1.
      • 0
        @ 2023-4-18 20:54:29

        #include <bits/stdc++.h> using namespace std; typedef long long LL;

        LL n;

        LL Pow(LL a, LL b, LL mod) { LL res = 1; while (b) { if (b&1) res = (resa)%mod; a = (aa)%mod; b >>= 1; } return res; }

        LL Euler(LL x) { LL res = x; for (int i = 2;i <= x;i++) { if (x%i == 0) { while (x % i == 0) x /= i; res = res/i*(i - 1); } } if (x > 1) res = res/x*(x-1); return res; }

        LL Solve(int cnt, LL mod) { LL res = 1e18; for (LL i = 1;i*i <= cnt;i++) { if (cnt%i == 0) { // cout << i << endl; if (Pow(10, i, mod) == 1) res = min(res, i); if (Pow(10, cnt/i, mod) == 1) res = min(res, cnt/i); } } if (res == 1e18) return 0; return res; }

        int main() { int cnt = 0; while (~scanf("%lld", &n) && n) { LL eul = Euler((9LLn)/__gcd(8LL, n9)); // cout << eul << endl; LL res = Solve(eul, (9LLn)/__gcd(8LL, n9)); printf("Case %d: %lld\n", ++cnt, res); }

        return 0;
        

        }

        • 1

        信息

        ID
        113
        时间
        1000ms
        内存
        128MiB
        难度
        8
        标签
        递交数
        12
        已通过
        10
        上传者