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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

codeforces B. Friends and Presents(二分+容斥)

發布時間:2025/3/8 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces B. Friends and Presents(二分+容斥) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:從1....v這些數中找到c1個數不能被x整除,c2個數不能被y整除!
并且這c1個數和這c2個數沒有相同的!給定c1, c2, x, y, 求最小的v的值!

思路: 二分+容斥,二分找到v的值,那么s1 = v/x是能被x整除的個數
s2 = v/y是能被y整除數的個數,s3 = v/lcm(x, y)是能被x,y的最小公倍數
整除的個數!
那么 v-s1>=c1 && v-s2>=c2 && v-s3>=c1+c2就是二分的條件!

1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 using namespace std; 6 7 int gcd(int x, int y){ 8 return y==0 ? x : gcd(y, x%y); 9 } 10 11 int lcm(int x, int y){ 12 return x*y/gcd(x, y); 13 } 14 15 int main(){ 16 long long ld = 1, rd = 100000000000000ll, mid; 17 long long c1, c2, x, y; 18 cin>>c1>>c2>>x>>y; 19 while(ld <= rd){ 20 mid = (ld + rd)>>1; 21 long long s1 = mid/x, s2 = mid/y, s3 = mid/lcm(x, y); 22 if(mid-s1 >= c1 && mid-s2 >= c2 && mid-s3 >= c1+c2) rd = mid-1; 23 else ld = mid+1; 24 } 25 cout<<rd+1<<endl; 26 return 0; 27 } View Code

?

轉載于:https://www.cnblogs.com/hujunzheng/p/4049969.html

總結

以上是生活随笔為你收集整理的codeforces B. Friends and Presents(二分+容斥)的全部內容,希望文章能夠幫你解決所遇到的問題。

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