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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

nyoj-Color the necklace(Ploya定理 + 欧拉函数 + 扩展欧几里得(求逆元))

發布時間:2025/3/16 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nyoj-Color the necklace(Ploya定理 + 欧拉函数 + 扩展欧几里得(求逆元)) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:http://acm.nyist.net/JudgeOnline/problem.php?pid=688

此題題解 不太懂,因為對這些概念,定理太模糊,理解起來比較困難,不過想想還是應該把代碼寫出來;


題意:給你一個數 n ,代表 n 種顏色和n個珠子,問你可以組合多少種長度為n的項鏈;不需要用掉n種顏色,項鏈的旋轉和翻轉都是為同一條

題解:?http://pan.baidu.com/s/1ntwPVkd#dir/path=%2FACM%E5%A5%97%E9%A2%98%2F09%E5%B9%B4%20-%203rd%20Central%20South%20China%20Programming%20Contest%2Fcsc2009%2FC%2Fsolution

點進去之后點擊C.ppt


公式:


#include<stdio.h> #include<math.h> #include<string.h> #include<algorithm> using namespace std; typedef long long LL; const LL mod = 20090531; LL x,y; LL euler(LL p)//歐拉定理 {LL res = p;for(LL i = 2;i <= sqrt(p);i++){if(p%i==0){while(p%i==0) p/=i;res = res/i*(i-1);}}if(p > 1) res = res / p * (p-1);return res%mod; } LL fast_pow(LL a,LL b)//快速冪 {LL res = 1;while(b){if(b&1) res = (res * a) % mod;a = (a * a) % mod;b >>= 1;}return res; } void edgcd(LL a,LL b)//求逆元 {if(b == 0){x = 1;y = 0;return;}edgcd(b,a%b);LL temp = x;x = y;y = temp - a/b*y; } void solve(LL m) {LL res = 0;for(LL i = 1;i <= sqrt(m);i++){if(m%i==0){if(m/i != i) res = (res + euler(i)*fast_pow(m,m/i-1))%mod;res = (res + euler(m/i)*fast_pow(m,i-1))%mod;}}if(m&1){res = (fast_pow(m,(m+1)/2) + res) % mod;edgcd(2,mod);}else{res = (fast_pow(m,m/2+1) + fast_pow(m,m/2) + 2 * res) % mod;edgcd(4,mod);}while(x < 0) x = (x + mod) % mod;printf("%lld\n",x * res % mod); } int main() {int n;LL m;scanf("%d",&n);while(n--){scanf("%lld",&m);solve(m);} }

總結

以上是生活随笔為你收集整理的nyoj-Color the necklace(Ploya定理 + 欧拉函数 + 扩展欧几里得(求逆元))的全部內容,希望文章能夠幫你解決所遇到的問題。

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