日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

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

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

擴展歐拉的第一題
參考??
參考

#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]; //注意要使用無符號形 Ull phi(Ull n){ //歐拉函數值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; //求斐波那契數的循環節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(){ //這道題主要運用了兩個性質: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的歐拉函數值int k,t; //2.斐波那契數列有一個性質,它的n次方取模會出現一個循環節.假設循環節長度為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時,模一定為0printf("0\n");continue;} //根據以上性質本題變為求F(a^b)^(F(a^b)^(n-1))%c(F()為斐波那契)ph=phi(c); //先求出歐拉函數值l=loop(c); //求循環cur=quickmod(a,b,l);cur=f[cur]; //求出F[a^b%len]if(ph==1){ //歐拉函數為1時單獨考慮cout<<quickmod(cur,n-1,c)<<endl;continue;}l=loop(ph);sum=quickmod(a,b,l);sum=f[sum]; //求出關于歐拉函數值F[a^b%len]sum=quickmod(sum,n-1,ph)+ph;cur=quickmod(cur,sum,c); //從而求出結果cout<<cur<<endl;}return 0; }

?

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。