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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)G GCD Guessing Game

發(fā)布時間:2024/4/13 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)G GCD Guessing Game 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

G:

  要你去才Paul的年齡,Paul的年齡在1~n之間,你每猜一個Paul會告訴你,你猜的這個數(shù)和他年齡的gcd,問在最壞情況下最少要猜多少次。

題解:

  什么是最壞情況,我們直到如果他的年齡是1的話, 你需要猜一邊全部素數(shù)。所以很明顯這就是最壞情況,

  如果p,q是素數(shù),p*q<=n, 我們就可以猜p*q,一次就可以去掉兩個素數(shù)了。

  所以這一題就變成了將1~n的素數(shù)分成m部分, 每一部分的乘積要小于等于n。

?

1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <string> 6 #include <algorithm> 7 #include <cmath> 8 #include <ctime> 9 #include <vector> 10 #include <queue> 11 #include <map> 12 #include <stack> 13 #include <set> 14 using namespace std; 15 typedef long long LL; 16 typedef unsigned long long uLL; 17 #define ms(a, b) memset(a, b, sizeof(a)) 18 #define pb push_back 19 #define mp make_pair 20 #define eps 0.0000000001 21 #define IOS ios::sync_with_stdio(0);cin.tie(0); 22 #define random(a, b) rand()*rand()%(b-a+1)+a 23 const LL INF = 0x3f3f3f3f3f3f3f3f; 24 const int inf = 0x3f3f3f3f; 25 const int maxn = 10000+10; 26 const int mod = 1e9+7; 27 int prime[maxn]; 28 int main() { 29 #ifdef LOCAL 30 freopen("input.txt", "r", stdin); 31 // freopen("output.txt", "w", stdout); 32 #endif 33 34 35 freopen("gcd.in", "r", stdin); 36 freopen("gcd.out", "w", stdout); 37 // IOS 38 int n; 39 scanf("%d", &n); 40 ms(prime, 0); 41 for(int i = 2;i<=n;i++){ 42 if(!prime[i]) prime[++prime[0]] = i; 43 for(int j = 1;j<=prime[0]&&prime[j]<=n/i;j++){ 44 prime[prime[j]*i] = 1; 45 if(i%prime[j]==0) break; 46 } 47 } 48 int L = 1, R = prime[0]; 49 int ans = 0; 50 while(L<=R){ 51 int p = prime[R]; 52 while(prime[L]*p<=n){ 53 p *= prime[L]; 54 L++; 55 } 56 ans++; 57 R--; 58 } 59 printf("%d\n", ans); 60 return 0; 61 } View Code

?

轉(zhuǎn)載于:https://www.cnblogs.com/denghaiquan/p/7439742.html

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

總結(jié)

以上是生活随笔為你收集整理的ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)G GCD Guessing Game的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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