数学/Codeforces 483b Friends and Presents

 1 #include<cstdio>
 2 using namespace std;
 3 long long m,cnt1,cnt2,x,y;
 4 long long gcd(long long a,long long b)
 5 {
 6     if (b==0) return a;
 7     return gcd(b,a % b);
 8 }
 9 long long lcm(long long a,long long b)
10 {
11     return a*b/gcd(a,b);
12 }
13 bool f(long long n)
14 {
15     long long xx=n-n/x,yy=n-n/y;
16     if (xx<cnt1 || yy<cnt2) return false;
17     long long both=n/m;
18     if ((n-both)<cnt1+cnt2) return false;
19     return true;
20 }
21 int main()
22 {
23     scanf("%lld%lld%lld%lld",&cnt1,&cnt2,&x,&y);
24     m=lcm(x,y);
25     long long l=1,r=1e10;
26     while (l<r)
27     {
28         long long mid=(l+r)/2;
29         if (f(mid)) r=mid;
30         else l=mid+1;
31     }
32     printf("%lld\n",r);
33     return 0;
34 }
时间: 2024-08-15 09:29:18

数学/Codeforces 483b Friends and Presents的相关文章

Codeforces 483B Friends and Presents(二分+数论)

题目链接:Codeforces 483B Friends and Presents 题目大意:要将1~v直间的数分配到两个集合中,第一个集合需要cnt1个数,第二个需要cnt2个数,第一个集合中的数 不能是x的倍数,同理第二个集合不能是y的倍数,两集合元素不能相同,问说v最小可以为多少. 解题思路:这题比第三题要难,想了有一会.二分答案,v,然后判断. 判断的时候只要分别判断集合一,二个数是否满足,但是因为有些数可以被分到两个集合,所以要判断总的可分配个数 是否满足大于cnt1+cnt2,计算总

CodeForces 483B Friends and Presents

Friends and Presents Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 483B Description You have two friends. You want to present each of them several positive integers. You want to presen

Codeforces 483B - Friends and Presents(二分+容斥)

483B - Friends and Presents 思路:这个博客写的不错:http://www.cnblogs.com/windysai/p/4058235.html 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset((a),(b),sizeof(a)) const ll INF=1e18; ll c1,c2,

Codeforces 483B - Friends and Presents - [二分]

题目链接:http://codeforces.com/contest/483 A - Counterexample - [简单构造题] Your friend has recently learned about coprime numbers. A pair of numbers $(a,?b)$ is called coprime if the maximum number that divides both $a$ and $b$ is equal to one. Your friend

贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet

题目传送门 1 /* 2 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 using namespace std; 8 9 const int MAXN = 11; 10 const int INF = 0x3f3f3f3f; 11 char s[MAXN][MAXN]; 12 1

数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

题目传送门 1 /* 2 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 3 另外不足一个区间的直接计算个数就可以了 4 */ 5 #include <cstdio> 6 #include <cmath> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 using namespace std; 11 12 typedef

数学 Codeforces Round #282 (Div. 2) B. Modular Equations

题目传送门 题意:a % x == b,求符合条件的x有几个 数学:等式转换为:a == nx + b,那么设k = nx = a - b,易得k的约数(>b)的都符合条件,比如a=25 b=1,那么24,12, 8, 6, 4, 3, 2都可以,所以只要求出k的约数有几个就可以了,a <= b的情况要特判 /************************************************* Author        :Running_Time* Created Time  

数学/CodeForces 485A Factory

1 /* 2 PROBLEM:CF 485A 3 AUTHER:Nicole 4 MEMO:数学 5 */ 6 7 #include<cstdio> 8 using namespace std; 9 int main() 10 { 11 int a,m; 12 scanf("%d%d",&a,&m); 13 int flag[100010]={0}; 14 int f=1; 15 while (f==1) 16 { 17 a=(a+a)%m; 18 if (

数学/CodeForces 483a Counterexample

1 /* 2 PROBLEM:CF 483A 3 AUTHER:Nicole 4 MEMO:数学 5 */ 6 #include<cstdio> 7 using namespace std; 8 int main() 9 { 10 long long l,r; 11 scanf("%lld%lld",&l,&r); 12 if (l%2!=0) l++; 13 //printf("%lld %lld\n",l,r); 14 if (r-l