Joty and Chocolate
来源:互联网 发布:怎么在电脑上登录淘宝 编辑:程序博客网 时间:2024/05/16 10:16
Description
Little Joty has got a task to do. She has a line ofn tiles indexed from 1 to n. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible bya and an unpainted tile should be painted Blue if it's index is divisible byb. So the tile with the number divisible bya and b can be either painted Red or Blue.
After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get.
Input
The only line contains five integers n, a, b, p and q (1 ≤ n, a, b, p, q ≤ 109).
Output
Print the only integer s — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use64-bit integer type to store it. In C++ you can use the long long integer type and inJava you can use long integer type.
Sample Input
5 2 3 12 15
39
20 2 3 3 5
51
题意:
有1到n个数,如果i%a==0,那么给p,如果i%b==0,那么给q,如果k%a==0||k%b==0,那么给p或者q,问你最多能给多少,显然肯定给p,q中大的那一个
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;long long gcd(long long a,long long b)//貌似叫容斥原理,求a,b最大公约数{ if(b==0) return a; return gcd(b,a%b);}long long gbs(long long a,long long b)//求a,b最小公倍数,数学像我一样渣的自行查资料{ return a*b/gcd(a,b);}int main(){ int n,a,b; long long p,q,sum,num1,num2,num3; scanf("%d%d%d%I64d%I64d",&n,&a,&b,&p,&q); num1=n/a; num2=n/b; num3=n/gbs(a,b); printf("%I64d\n",(num1-num3)*p+(num2-num3)*q+num3*max(q,p)); return 0;}
- D - Joty and Chocolate
- Joty and Chocolate
- Joty and Chocolate
- Codeforces 678 C. Joty and Chocolate
- Codeforces-678C-Joty and Chocolate
- codeforces 678C Joty and Chocolate
- Codeforces 678C Joty and Chocolate
- Educational Codeforces Round 13 C Joty and Chocolate(数学)
- codeforces 678C. Joty and Chocolate(容斥)
- codeforces-678-C. Joty and Chocolate(数学)
- Alice, Bob and Chocolate
- Codeforces Jzzhu and Chocolate
- cf450C. Jzzhu and Chocolate
- Mike and Chocolate Thieves
- Alice, Bob and Chocolate
- G - Alice, Bob and Chocolate
- 450C - Jzzhu and Chocolate
- Alice, Bob and Chocolate CodeForces
- 获得唯一标识符——时间戳、GUID
- hdu 5804 Price List
- 倒计时
- 洛谷1156 垃圾陷阱(背包动规)
- 信息安全工具集
- Joty and Chocolate
- LeetCode | Longest Substring Without Repeating Characters
- Struts2与Struts的区别
- Git常用命令快速回顾(一)
- mysql入门
- Android基于环信SDK开发IM即时聊天
- Java await和sleep的区别
- Java异常处理和设计
- 火车票购票问题1