日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

【HDU 2814 扩展欧拉 a^b ≡ (a mod c)^b mod ϕ(c)+ϕ(c) modc,b=ϕ(c) 】

發(fā)布時(shí)間:2025/4/16 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU 2814 扩展欧拉 a^b ≡ (a mod c)^b mod ϕ(c)+ϕ(c) modc,b=ϕ(c) 】 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

G(1)=F(ab)G(1)=F(ab)?
G(n)=G(n?1)F(ab)(n>=2)G(n)=G(n?1)F(ab)(n>=2)
求G(n)modc

具體:
In mathematics, the Fibonacci numbers are a sequence of numbers named after Leonardo of Pisa, known as Fibonacci (a contraction of filius Bonaccio, "son of Bonaccio"). Fibonacci's 1202 book Liber Abaci introduced the sequence to Western European mathematics, although the sequence had been previously described in Indian mathematics.?
??The first number of the sequence is 0, the second number is 1, and each subsequent number is equal to the sum of the previous two numbers of the sequence itself, yielding the sequence 0, 1, 1, 2, 3, 5, 8, etc. In mathematical terms, it is defined by the following recurrence relation:?
?
That is, after two starting values, each number is the sum of the two preceding numbers. The first Fibonacci numbers (sequence A000045 in OEIS), also denoted as F[n];?
F[n] can be calculate exactly by the following two expressions:?
?
?
A Fibonacci spiral created by drawing arcs connecting the opposite corners of squares in the Fibonacci tiling; this one uses squares of sizes 1, 1, 2, 3, 5, 8, 13, 21, and 34;?

So you can see how interesting the Fibonacci number is.?
Now AekdyCoin denote a function G(n)?
?
Now your task is quite easy, just help AekdyCoin to calculate the value of G (n) mod C

Input
The input consists of T test cases. The number of test cases (T is given in the first line of the input. Each test case begins with a line containing A, B, N, C (10<=A, B<2^64, 2<=N<2^64, 1<=C<=300)

Output
For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the value of G(N) mod C

Sample Input
1 17 18446744073709551615 1998 139

Sample Output
Case 1: 120

擴(kuò)展歐拉的第一題
參考??
參考

#include <bits/stdc++.h> #define X 10005 #define inF 0x3f3f3f3f #define PI 3.141592653589793238462643383 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; typedef long long ll; //2^32 typedef unsigned long long Ull; //2^64 const int maxn = 1e6 + 10; const int Times = 10; const ll inf = 9223372036854775807; int N = 1e6 + 10; int primer[maxn], a[maxn]; Ull f[20005]; //注意要使用無符號(hào)形 Ull phi(Ull n){ //歐拉函數(shù)值ll sum=n,i;for(i=2;i*i<=n;i++){if(n%i==0){sum-=sum/i;while(n%i==0)n/=i;}}if(n>1)sum-=sum/n;return sum; } Ull quickmod(Ull a,Ull b,Ull m){Ull sum=1; //快速冪a=a%m;while(b){if(b&1)sum=sum*a%m;b>>=1;a=a*a%m;}return sum; } Ull loop(Ull m){ll i; //求斐波那契數(shù)的循環(huán)節(jié)f[0]=0;f[1]=1;f[2]=1;for(i=3;;i++){f[i]=(f[i-1]+f[i-2])%m;if(f[i]==f[1]&&f[i-1]==f[0])return i-1;} } int main(){ //這道題主要運(yùn)用了兩個(gè)性質(zhì):Ull a,b,n,c,i,j,l,ph,cur,sum;//1.a^b ≡ (a mod c)^b mod ?(c)+?(c) modc,b>=?(c) ?(c)為c的歐拉函數(shù)值int k,t; //2.斐波那契數(shù)列有一個(gè)性質(zhì),它的n次方取模會(huì)出現(xiàn)一個(gè)循環(huán)節(jié).假設(shè)循環(huán)節(jié)長(zhǎng)度為len,// 則F(a^b) modc = F(a^bmod len)modccin>>t;for(k=1;k<=t;k++){cin>>a>>b>>n>>c;printf("Case %d: ",k);if(c==1){ //c等于0時(shí),模一定為0printf("0\n");continue;} //根據(jù)以上性質(zhì)本題變?yōu)榍驠(a^b)^(F(a^b)^(n-1))%c(F()為斐波那契)ph=phi(c); //先求出歐拉函數(shù)值l=loop(c); //求循環(huán)cur=quickmod(a,b,l);cur=f[cur]; //求出F[a^b%len]if(ph==1){ //歐拉函數(shù)為1時(shí)單獨(dú)考慮cout<<quickmod(cur,n-1,c)<<endl;continue;}l=loop(ph);sum=quickmod(a,b,l);sum=f[sum]; //求出關(guān)于歐拉函數(shù)值F[a^b%len]sum=quickmod(sum,n-1,ph)+ph;cur=quickmod(cur,sum,c); //從而求出結(jié)果cout<<cur<<endl;}return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的【HDU 2814 扩展欧拉 a^b ≡ (a mod c)^b mod ϕ(c)+ϕ(c) modc,b=ϕ(c) 】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。