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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu 4983 Goffi and GCD(欧拉函数)

發(fā)布時間:2024/4/14 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 4983 Goffi and GCD(欧拉函数) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Problem Description

Goffi is doing his math homework and he finds an equality on his text book:?gcd(n?a,n)×gcd(n?b,n)=nk.

Goffi wants to know the number of (a,b) satisfy the equality, if?n?and?k?are given and?1a,bn.

Note:?gcd(a,b)?means greatest common divisor of?a?and?b.

?

Input Input contains multiple test cases (less than 100). For each test case, there's one line containing two integers?n?and?k?(1n,k109).

?

Output For each test case, output a single integer indicating the number of (a,b) modulo?109+7.

?

Sample Input 2 1
3 2

?

?

Sample Output 2 1

?


Hint For the first case, (2, 1) and (1, 2) satisfy the equality.

?

Source BestCoder Round #6 ?發(fā)現(xiàn)自己歐拉函數(shù)都給忘記了,所有趕緊補題。。。 1、k!=1時情況很簡單,記住將if(k==2 || n==1)這個特判放在if(k>2)的前面,因為這個WA了很久,各種原因自己思考。 2、下面討論k=1時情況。x=gcd(n-a,n),則n/x=gcd(n-b,n),因為n-a可以取到0...n-1也就是1....n,所以完全可以去掉n-這個限制條件,即gcd(a,n)=x、gcd(b,n)=n/x時個數(shù),因為a<=n,所以gcd(a,n)的個數(shù)=u[n/x],u是歐拉函數(shù)。所以原式等于sigma(u[n/x]*u[x])其中x是n的約數(shù)。

?

1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 #define MOD 1000000007 6 #define ll long long 7 ll eular(ll n) 8 { 9 ll res=1; 10 for(ll i=2;i*i<=n;i++) 11 { 12 if(n%i==0) 13 { 14 n/=i,res*=i-1; 15 while(n%i==0) 16 { 17 n/=i; 18 res*=i; 19 } 20 } 21 } 22 if(n>1) res*=n-1; 23 return res; 24 } 25 ll n,k; 26 int main() 27 { 28 while(scanf("%I64d%I64d",&n,&k)==2) 29 { 30 if(k==2 || n==1) 31 { 32 printf("1\n"); 33 continue; 34 } 35 if(k>2) 36 { 37 printf("0\n"); 38 continue; 39 } 40 41 ll ans=0; 42 for(ll i=1;i*i<=n;i++) 43 { 44 if(n%i==0) 45 { 46 if(i*i!=n) 47 ans=(ans+eular(n/i)*eular(i)*2)%MOD; 48 else 49 ans=(ans+eular(n/i)*eular(i))%MOD; 50 } 51 } 52 printf("%I64d\n",ans); 53 54 } 55 return 0; 56 } View Code

?

超強干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生

總結(jié)

以上是生活随笔為你收集整理的hdu 4983 Goffi and GCD(欧拉函数)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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