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. python 之datetime库学习

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

  2. Intel大坑之一:丢失的SSE2 128bit/64bit 位移指令,马航MH370??

    缘由 最近在写一些字符串函数的优化,兴趣使然,可是写的过程中,想要实现 128bit 的按 bit 逻辑位移,遇到了一个大坑,且听我娓娓道来. 如果要追究标题,更确切的是丢失的SSE2 128 bit ...

  3. PHP计算字符串的长度

    <?php /** * 计算字符串的长度(汉字按照两个字符计算) * * @param string $str 字符串 * * @return int */ function str_len($ ...

  4. XP远程连接Win10,提示【远程计算机需要网络级别身份验证,而您的计算机不支持该验证】

    最近电脑安装了Win10系统,在办公室可以通过其他电脑远程,但是回去后使用自己的电脑(XP系统)进行远程提示失败, 提示[远程计算机需要网络级别身份验证,而您的计算机不支持该验证],然后上网查找资料, ...

  5. Java HashCode详解

    一.为什么要有Hash算法 Java中的集合有两类,一类是List,一类是Set.List内的元素是有序的,元素可以重复.Set元素无序,但元素不可重复.要想保证元素不重复,两个元素是否重复应该依据什 ...

  6. linux用户操作

    1.用户种类 Linux具有三种用户: 超级管理员root:具有最高权限,UID=0  GID=0伪用户(System Account):(UID=1~499)普通用户(login-Account): ...

  7. 为什么有些网页QQ浏览器右键没有检查

    改成[极速内核]. 设置->高级设置 改成[极速内核]: 如下图:

  8. Monaco Editor 使用入门

    以前项目是用ace编辑器的,但是总有些不敬人意的地方.前端事件看见的VS Code编辑器Monaco Editor准备更换下,下面介绍一些使用中遇到的一点问题.代码提示 1.项目引用 import * ...

  9. PHP 识别 java 8位 des 加密和 解密方式

    代码及使用说明: <?php /** *PHP 识别 java 8位密钥的加密和解密方式 *@desc 加密方式 通用 */ class DES { var $key; var $iv; //偏 ...

  10. USACO 6.5 Betsy's Tour (插头dp)

    Betsy's TourDon Piele A square township has been divided up into N2 square plots (1 <= N <= 7) ...