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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

[HDU 4344]Mark the Rope(Pollard_rho+Miller_Rabin)

發布時間:2024/4/13 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [HDU 4344]Mark the Rope(Pollard_rho+Miller_Rabin) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Description

Eric has a long rope whose length is N, now he wants to mark on the rope with different colors. The way he marks the rope is:
1. He will choose a color that hasn’t been used
2. He will choose a length L (N>L>1) and he defines the mark’s value equals L
3. From the head of the rope, after every L length, he marks on the rope (you can assume the mark’s length is 0 )
4. When he chooses the length L in step 2, he has made sure that if he marks with this length, the last mark will be at the tail of the rope
Eric is a curious boy, he want to choose K kinds of marks. Every two of the marks’ value are coprime(gcd(l1,l2)=1). Now Eric wants to know the max K. After he chooses the max K kinds of marks, he wants to know the max sum of these K kinds of marks’ values.
You can assume that Eric always can find at least one kind of length to mark on the rope.

Solution

質因數分解一下就好了,應該是道模板題

然而我忘記還有質因數只有一個的情況,L不能等于N啊

QvQ拍了好久都沒找到錯在哪,后來隨手輸了個1024發現事情有蹊蹺…

#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<vector> #include<map> using namespace std; typedef long long LL; LL T,ans=0; vector<LL>v; map<LL,LL>num; LL gcd(LL a,LL b) {return b?gcd(b,a%b):a; } LL mul(LL a,LL b,LL p) {LL res=0;while(b){if(b&1)res=(res+a)%p;a=(a+a)%p;b>>=1;}return res; } LL pow(LL a,LL n,LL p) {LL res=1;while(n){if(n&1)res=mul(res,a,p);a=mul(a,a,p);n>>=1;}return res; } bool check(LL a,LL n,LL m,LL cnt) {LL x=pow(a,m,n),y=x;for(int i=1;i<=cnt;i++){x=mul(x,x,n);if(x==1&&y!=1&&y!=n-1)return 1;y=x;}return x!=1; } bool Miller_Rabin(LL n) {if(n==2)return 1;if(n<=1||n&1==0)return 0;LL m=n-1,cnt=0;while(m&1==0)cnt++,m>>=1;for(int i=1;i<=7;i++){if(check(rand()%(n-1)+1,n,m,cnt))return 0;}return 1; } LL rho(LL n,LL c) {LL i=1,k=2,x=rand()%(n-1)+1,y=x,d;while(1){x=(mul(x,x,n)+c)%n;d=x>y?gcd(x-y,n):gcd(y-x,n);if(d>1)return d;if(y==x)return n;if(i==k)y=x,k<<=1;i++;} } void solve(LL n) {if(n==1)return;if(Miller_Rabin(n)){if(!num[n]){v.push_back(n),ans++,num[n]=1;}num[n]*=n;return;}LL p=n;while(p==n)p=rho(n,rand()%(n-1)+1);solve(p);solve(n/p); } int main() {scanf("%lld",&T);while(T--){LL n;scanf("%lld",&n);v.clear(),num.clear(),ans=0;solve(n);if(v[0]==n)ans--;printf("%lld ",ans);LL sum=0;for(int i=0;i<ans;i++)sum+=num[v[i]];if(ans==1)sum/=v[0];printf("%lld\n",sum);}return 0; }

?

轉載于:https://www.cnblogs.com/Zars19/p/6840576.html

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的[HDU 4344]Mark the Rope(Pollard_rho+Miller_Rabin)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 欧美不卡一二三 | 久久a视频| 国产思思 | 日韩中文字幕久久 | 亚洲国产日韩一区二区 | 国产精品久久久久久人妻精品动漫 | 先锋影音av资源网站 | 久久精品无码Av中文字幕 | 九九热精品视频 | 毛片一级在线观看 | 好爽又高潮了毛片 | 亚洲视频a | 麻豆视屏 | 乖女从小调教h尿便器小说 欧美韩一区二区 | 国内免费毛片 | 午夜影院一区二区 | 亚洲三级在线看 | 日韩经典午夜福利发布 | 国产一区二区三区在线视频观看 | 久爱视频在线观看 | 黄色一级片视频 | 亚洲美女免费视频 | 1024手机在线看片 | 天天操天天添 | 男男av网站 | 亚洲色图狠狠干 | 午夜黄色大片 | 亚欧乱色 | 日韩免费看片 | 精品电影在线观看 | 天天搞天天干 | 免费精品无码AV片在线观看黄 | 99人妻少妇精品视频一区 | 春意影院福利社 | xxxxx毛片| 欧美高清精品一区二区 | 久久亚洲国产成人精品性色 | 伊伊成人网| 亚洲精品人妻无码 | 精品少妇无码av无码专区 | 中文字字幕| 亚洲字幕在线观看 | 成人毛片100部免费看 | 粉嫩av一区二区三区免费观看 | 毛茸茸毛片 | 久久精品人妻av一区二区三区 | 亚洲综合五月天 | 成人毛片18女人毛片免费 | 国产偷人妻精品一区二区在线 | 明星毛片| 亚洲精品视屏 | 男女搞网站 | 欧美日韩一区二区三区免费 | 国产探花视频在线观看 | 亚洲av无码国产精品麻豆天美 | 欧美日韩亚洲国产一区 | 四虎最新站名点击进入 | 免费视频久久 | 亚洲av成人无码久久精品老人 | 亚洲国产精品久久AV | 精品99久久久久成人网站免费 | 成人动漫免费观看 | www.国产毛片 | 国产亚洲一区在线 | 欧洲女女同性videoso | 精品人妻无码专区在线 | 国产精品久久视频 | 欧美三区在线观看 | 午夜裸体性播放 | www.狠狠艹| 国模小黎自慰gogo人体 | 三级a做爰全过程 | 日韩中文字幕不卡 | 狠狠爱婷婷 | 国产xxxxx| 国产精品久久久久毛片软件 | www.com欧美 | 免费看黄的网址 | 懂色一区二区二区av免费观看 | 美女啪啪一区二区 | 欧美日韩国产区 | 久久性网| 日韩欧美在线观看一区 | jzzijzzij亚洲成熟少妇在线观看 久久久精品人妻一区二区三区 | 欧美性69| 人人妻人人澡人人爽人人精品 | 欧美天天搞 | 激情小说欧美色图 | 国产又粗又猛又爽又黄无遮挡 | 久久91av | 色欧美日韩 | 欧美视频在线不卡 | 扒开美女内裤狂揉下部 | 亚洲精品成人区在线观看 | 亚洲蜜臀av | 国产美女91呻吟求 | 亚洲av无码一区二区三区网站 | 无码精品人妻一二三区红粉影视 | 天天网综合 |