标签:
Description
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 byb. 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 long integer type.
5 2 3 12 15
39
20 2 3 3 5
51
一个简单的容斥,我们先算a再算b,再求能被a和b一起整除的,然后算出单独被a,b整除的,一起整除的我们选最大的去乘
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include<algorithm> 5 using namespace std; 6 int main() 7 { 8 long long n,a,b,p,q; 9 long long ans1,ans2,ans3,ans4,ans5; 10 cin>>n>>a>>b>>p>>q; 11 ans1=n/a;ans2=n/b;ans3=a/__gcd(a,b)*b;ans4=n/ans3; 12 cout<<(ans1-ans4)*p+(ans2-ans4)*q+ans4*max(p,q)<<endl; 13 return 0; 14 }
Educational Codeforces Round 13 C
标签:
原文地址:http://www.cnblogs.com/yinghualuowu/p/5588695.html