UVA-11582 Colossal Fibonacci numbers! Cycle Festival

Source: Internet
Author: User

Looking for Fn = (Fn-1 + Fn-2) mod n's Loop section

Violence can be found

1#include <cstdio>2#include <iostream>3#include <cstring>4typedef unsignedLong Longll;5 using namespacestd;6 Const intMAXN =1023;7ll f[maxn][maxn*Ten];8 intCIRCLE[MAXN];9 Ten voidinit () { One      for(intK =2; k<= +; k++){ Af[k][0] =0, f[k][1] =1; -          for(inti =2; ; i++){ -F[k][i] = (f[k][i-1] + f[k][i-2])%K; the             if(F[k][i] = =1&& f[k][i-1] ==0){ -Circle[k] = i1; -                  Break; -             } +         } -     } + } A ll Quick_mod (ll A, ll B, ll MoD) { atll ans =1; -      while(B >0){ -         if(b&1){ -b--; -Ans = ans*a%MoD; -         } inb >>=1; -A = a*a%MoD; to     } +     returnans; - } the voidSlove (ll A, ll B,intN) { *     intres = Quick_mod (a%Circle[n], B, Circle[n]); $cout << F[n][res] <<Endl;Panax Notoginseng } - intMain () { the     //freopen ("Data.in.txt", "R", stdin); +    //freopen ("Data.out.txt", "w", stdout); A     intt, N; the ll A, B; + init (); -scanf"%d", &t); $      while(t--) { $Cin >> a >> b >>N; -         if(n = =1|| A = =0) cout<<0<<Endl;; -         ElseSlove (A, B, n); the     } -     return 0;Wuyi}

UVA-11582 Colossal Fibonacci numbers! Cycle Festival

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.