码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 13 C

时间:2016-06-15 20:35:29      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

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.

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
一个简单的容斥,我们先算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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!