• uva 11582


    斐波那契数论 求第 a^b 项 %c

    听说有循环结 

    #include<stdio.h>
    #include<algorithm>
    #include<cstring>
    #include<string>
    #include<cmath>
    
    using namespace std;
    
    #define MAXN 60010
    #define inf  1000000000.0
    
    unsigned long long z[10010];
    unsigned long long quick(unsigned long long a,unsigned long long b,unsigned long long c)
    {
        unsigned long long ans=1;
        a =  a % c;
        while(b>0)
        {
            if(b&1)
                ans = (ans * a) % c;
            b>>=1;
            a = (a * a) % c;
        }
        return ans;
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            unsigned long long a,b,n;
            scanf("%llu%llu%llu",&a,&b,&n);
            if(a==0 || n== 1)
            {
                printf("0
    ");
                continue;
            }
            z[0]=0;
            z[1]=1;
            unsigned long long c;
            for(int i=2;;i++)
            {
                 z[i]=(z[i-1]+z[i-2])%n;
                // printf("%llu ",z[i]);
                 if(z[i]==1&&z[i-1]==0)
                 {
                     c=i-1;
                     break;
                 }
            }
           // printf("
    ");
          //  printf("%llu
    ",c);
            unsigned long long ans;
            ans = quick(a,b,c);
            printf("%llu
    ",z[ans]);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    hdu 1106 排序(排序)
    hdu 1040 As Easy As A+B(排序)
    hdu 1029 Ignatius and the Princess IV(排序)
    mysql-9索引
    mysql-8 alter命令
    mysql-7事务管理
    mysql-6正则表达式
    http协议
    9-2交互体验
    9-2专项测试下午
  • 原文地址:https://www.cnblogs.com/cherryMJY/p/6508248.html
Copyright © 2020-2023  润新知