C. Joty and Chocolate

题目连接:

http://www.codeforces.com/contest/678/problem/C

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 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 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 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.

Sample Input

5 2 3 12 15

Sample Output

39

Hint

题意

有1到n n个数,如果k%a0,那么给p元,如果k%b0,那么给q元

如果k%a0||k%b0,那么给p元或者q元

问你最多给多少

题解:

k%a0||k%b0 > k%lcm(a,b)0 给max(p,q)元

然后搞一波就好了……

代码

#include<bits/stdc++.h>
using namespace std; long long gcd(long long a,long long b)
{
if(b==0)return a;
return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
return a*b/gcd(a,b);
}
long long n,a,b,p,q;
int main()
{
cin>>n>>a>>b>>p>>q;
long long ans1 = n/a;
long long ans2 = n/b;
long long ans3 = n/lcm(a,b);
ans1-=ans3,ans2-=ans3;
cout<<ans1*p+ans2*q+(ans3)*max(p,q)<<endl;
}

Educational Codeforces Round 13 C. Joty and Chocolate 水题的更多相关文章

  1. Educational Codeforces Round 13 D. Iterated Linear Function 水题

    D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...

  2. Educational Codeforces Round 13 B. The Same Calendar 水题

    B. The Same Calendar 题目连接: http://www.codeforces.com/contest/678/problem/B Description The girl Tayl ...

  3. Educational Codeforces Round 13 A. Johny Likes Numbers 水题

    A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes ...

  4. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  5. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  6. Educational Codeforces Round 4 A. The Text Splitting 水题

    A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...

  7. Codeforces Educational Codeforces Round 3 B. The Best Gift 水题

    B. The Best Gift 题目连接: http://www.codeforces.com/contest/609/problem/B Description Emily's birthday ...

  8. Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题

    A. USB Flash Drives 题目连接: http://www.codeforces.com/contest/609/problem/A Description Sean is trying ...

  9. Educational Codeforces Round 12 A. Buses Between Cities 水题

    A. Buses Between Cities 题目连接: http://www.codeforces.com/contest/665/problem/A Description Buses run ...

随机推荐

  1. bzoj 1607 Patting Heads 轻拍牛头

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1607 题解: 题目似乎出错,应为“同时拍打所有所持纸条上的数字能被此牛所持纸条上的数字整除 ...

  2. jQuery基本筛选器-表单筛选器-关系筛选器

    一.基本筛选器 :first // 第一个 :last // 最后一个 :eq(index)// 索引等于index的那个元素 :even // 匹配所有索引值为偶数的元素,从 0 开始计数 :odd ...

  3. python 之datetime库学习

    # -*- coding:utf-8 -*- import refrom datetime import datetime, timezone, timedelta def rec_time():   ...

  4. Go 命令行总结

    go build:已当前目录作为package进行编译,将当前目录下的所有文件编译成package文件,文件名与所在的目录同名. go install: 分两步操作:1.先执行go build进行编译 ...

  5. IE手工导入证书

    打开cer文件->欢迎使用证书导入向导->下一步->将所有的证书放入下列存储->受信任的根证书颁发机构->完成

  6. 洛谷P1286 两数之和

    这个题.. 刚开始没看见输入若干行,所以有的点就.. 令 m = n * (n - 1) / 2 已知 s = {s (1), s(2), ..., s(m)}, s(i) <= s(i+1) ...

  7. Java输出文件到本地(输出流)

    package cn.buaa; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; im ...

  8. jQuery类名添加click方法

    通过$("").jQuery为元素添加点击事件,在使用类的情况下,可以使用$(e.target).attr('title');获得被点击元素的属性值. 示例代码如下 $(" ...

  9. SRILM语言模型格式解读

    先看一下语言模型的输出格式 \data\ ngram = ngram = ngram = \-grams: -5.24036 'cause -0.2084827 -4.675221 'em -0.22 ...

  10. mysql 删除重复项

    DELETE FROM j_rank_rise_record WHERE id NOT IN ( SELECT id FROM ( SELECT * FROM j_rank_rise_record g ...