• uva 11582 Colossal Fibonacci Numbers!


    //为啥循环节一定要是0 1开头

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<queue>
     8 #include<vector>
     9 #include<map>
    10 #include<stack>
    11 #include<string>
    12 
    13 using namespace std;
    14 
    15 const unsigned long long MAXN=1001;
    16 
    17 unsigned long long T;
    18 unsigned long long a,b;
    19 unsigned long long n;
    20 unsigned long long f[MAXN*MAXN];
    21 
    22 unsigned long long pow(unsigned long long a,unsigned long long b,unsigned long long n){
    23     unsigned long long tmp=a%n;
    24     unsigned long long ans=1;
    25     while (b!=0){
    26             if (b&1==1){
    27                     ans=(ans*tmp)%n;
    28             }
    29             tmp=(tmp*tmp)%n;
    30             b=b>>1;
    31     }
    32     //printf("%d
    ",ans);
    33     return ans;
    34 }
    35 
    36 int main(){
    37     scanf("%llu",&T);
    38     while (T--){
    39             scanf("%llu%llu%llu",&a,&b,&n);
    40             f[0]=0%n;
    41             f[1]=1%n;
    42             unsigned long long len;
    43             unsigned long long now=1;
    44             while (1){
    45                     f[now+1]=(f[now]+f[now-1])%n;
    46                     if (f[now]==f[0] && f[now+1]==f[1]){
    47                             len=now;
    48                             break;
    49                     }
    50                     now++;
    51             }
    52             //printf("%d
    ",len);
    53             printf("%llu
    ",f[pow(a,b,len)]);
    54     }
    55     return 0;
    56 }
    57 /*
    58 3
    59 1 1 2
    60 2 3 1000
    61 18446744073709551615 18446744073709551615 1000
    62 
    63 1
    64 18446744073709551615 18446744073709551615 1000
    65 */
    66 /*
    67 1
    68 21
    69 250
    70 */
    View Code
  • 相关阅读:
    练手
    课余时间娱乐下
    2017-2-19,作业
    JavaScript(下)
    JavaScript(上)
    Day15:网络编程-HTTP
    小知识:静态导入
    多线程知识点:锁
    多线程知识点:同步
    Day16:反射技术
  • 原文地址:https://www.cnblogs.com/baby-mouse/p/4632657.html
Copyright © 2020-2023  润新知