暑假第一周 B
来源:互联网 发布:linux安装binwalk 编辑:程序博客网 时间:2024/06/05 01:53
Little Joty has got a task to do. She has a line of n 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 by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a 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.
The only line contains five integers n, a, b, p and q (1 ≤ n, a, b, p, q ≤ 109).
Print the only integer s — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use longinteger type.
5 2 3 12 15
39
20 2 3 3 5
51
//B***********
#include<iostream>
#include<algorithm>
using namespace std;
long long gcd_(long long a, long long b){
long long big = max(a, b);
long long small = min(a, b);
long long temp = big % small;
return temp == 0 ? small : gcd_(small, temp);
}
int main(){
long long n,a,b,p,q;
while(cin>>n>>a>>b>>p>>q){
long long s=0;
s+=n/a*p;
s+=n/b*q;
long long tmp=a*b/(gcd_(a,b));
long long tm=n/tmp;
if(p>q){
s-=tm*q;
}
else{
s-=tm*p;
}
cout<<s<<endl;
}
return 0;
}
- 暑假第一周 B
- 暑假第一周 D CodeForces 660 B.
- 暑假的第一周
- 暑假第一周 I
- 暑假第一周 L
- 暑假第一周 A
- 暑假第一周 R
- 暑假第一周 E
- 暑假第一周 T
- 暑假集训第一周总结
- 暑假学习任务第一周
- 暑假留校--第一周总结
- 暑假第一周学习总结
- 暑假留校第一周总结
- 2013年暑假实习第一周总结
- 2015暑假集训第一周题目总结
- WUST暑假集训第一周简单小结
- 暑假第一周 F (水题)
- 位操作-leetcode 136. Single Number
- JS 函数length
- Intellij Idea 搭建J2EE项目入门
- 随笔二
- JS 函数call和apply
- 暑假第一周 B
- Session深度解析
- spring cloud拓扑图
- copy-list-with-random-pointer
- linux系统分析工具pidstat
- 为什么要面向接口编程
- design项目介绍
- 漏洞分析之CVE-2010-2883(栈溢出)
- android开发问题 Failed to pull selection