zoukankan      html  css  js  c++  java
  • FZU 1759 Super A^B mod C 指数循环节

    Problem 1759 Super A^B mod C

    Time Limit: 1000 mSec    Memory Limit : 32768 KB

     Problem Description

    Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000).

     Input

    There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space.

     Output

    For each testcase, output an integer, denotes the result of A^B mod C.

     Sample Input

    3 2 4 2 10 1000

     Sample Output

    1 24
    思路:指数循环节,数据水,并没有B<C&&A,C不互质的;
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll __int64
    #define esp 0.00000000001
    const int N=1e5+10,M=1e6+10,inf=1e9+10;
    const int mod=1000000007;
    #define MAXN 10000010
    ll quickpow(ll x,ll y,ll z)
    {
        ll ans=1;
        while(y)
        {
            if(y&1)
            ans*=x,ans%=z;
            x*=x;
            x%=z;
            y>>=1;
        }
        return ans;
    }
    ll phi(ll n)
    {
        ll i,rea=n;
        for(i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                rea=rea-rea/i;
                while(n%i==0)  n/=i;
            }
        }
        if(n>1)
            rea=rea-rea/n;
        return rea;
    }
    char a[M];
    int main()
    {
        ll x,y,z,i,t;
        while(~scanf("%I64d%s%I64d",&x,a,&z))
        {
            t=strlen(a);
            ll p=phi(z);
            ll ans=0;
            for(i=0;i<t;i++)
            ans=(ans*10+a[i]-'0')%p;
            ans+=p;
            printf("%I64d
    ",quickpow(x,ans,z));
        }
        return 0;
    }
  • 相关阅读:
    我深知黑暗,但心向光明(记毕业后第一次在北京求职)
    CF 1200E HASH模板
    CF580D
    CF1433F
    CF1451 E1交互题
    11.23-11.29 训练计划
    11.22 CF总结 #682
    sql问题:备份集中的数据库备份与现有的 '办公系统' 数据库不同
    内容导出成word
    让超链接无法跳转的方法
  • 原文地址:https://www.cnblogs.com/jhz033/p/5687629.html
Copyright © 2011-2022 走看看