codeforces 678C. Joty and Chocolate(容斥)
来源:互联网 发布:get it ? 编辑:程序博客网 时间:2024/05/18 01:35
题目的意思是给你1-n,n个数,你可以把a的倍数染成红色获得p价值,把b的倍数染成蓝色获得q价值,a,b公倍数任意一种颜色问最大价值
直接把a的倍数的和b的倍数的价值全加起来,公倍数染价值大的,即减去小的价值的即可
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<queue>#include<vector>#include<algorithm>using namespace std;#define inf 0x3f3f3f3flong long gcd(long long x,long long y){ if(y==0) return x; else return(gcd(y,x%y));}long long lcm(long long x,long long y){ return x*y/gcd(x,y);}int main(){long long n,a,b,p,q; while(~scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q)) { long long lm=lcm(a,b); printf("%lld\n",(n/a)*p+(n/b)*q-min(p,q)*(n/(lm))); } return 0;}
0 0
- codeforces 678C. Joty and Chocolate(容斥)
- Codeforces 678 C. Joty and Chocolate
- Codeforces-678C-Joty and Chocolate
- codeforces 678C Joty and Chocolate
- Codeforces 678C Joty and Chocolate
- codeforces-678-C. Joty and Chocolate(数学)
- Educational Codeforces Round 13 C Joty and Chocolate(数学)
- D - Joty and Chocolate
- Joty and Chocolate
- Joty and Chocolate
- Codeforces 678C Mike and Chocolate Thieves(二分)
- codeforces 6C - Alice, Bob and Chocolate
- Codeforces 450 C. Jzzhu and Chocolate
- Codeforces 450 C. Jzzhu and Chocolate
- codeforces #257 C题Jzzhu and Chocolate
- Codeforces Round #257 C.Jzzhu and Chocolate
- Codeforces 6C. Alice, Bob and Chocolate
- CodeForces 6C - Alice, Bob and Chocolate
- Opengl菜单
- C. Guess the Array(codeforces)
- Linux命令find之"exec"
- Android 异步消息处理机制 让你深入理解 Looper、Handler、Message三者关系
- 杨辉三角形
- codeforces 678C. Joty and Chocolate(容斥)
- Android隐藏标题栏
- 海底高铁
- window charles 乱码
- Tarjan(无向图双联通分量)——hihoCoder 1184
- C语言问答题1
- codeforces 28C (概率DP)
- 程序员提高效率的一些建议
- 硅谷并没有发明什么