Codeforces 678C Joty and Chocolate

来源:互联网 发布:ubuntu 17.04更新源 编辑:程序博客网 时间:2024/04/30 10:02

C. Joty and Chocolate
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The only line contains five integers nabp 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 use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Examples
input
5 2 3 12 15
output
39
input
20 2 3 3 5
output
51

题目大意:有下标为1到n的n个瓷砖,如果某个瓷砖下标能被a整除,那么就能获得p块巧克力,如果能被b整除,就能获得q块巧克力,如果同时被a和b整除,就随便你要哪种巧克力

如果能同时被a和b整除,肯定选最多的那一个啊

#include<iostream>using namespace std;typedef long long ll;ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}int main(){ll n,a,b,p,q;while(cin>>n>>a>>b>>p>>q){cout<<n/a*p+n/b*q-min(p,q)*(n/lcm(a,b))<<endl;}}


原创粉丝点击