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

题目的意思是给你1-n,n个数,你可以把a的倍数染成红色获得p价值,把b的倍数染成蓝色获得q价值,a,b公倍数任意一种颜色问最大价值

直接把a的倍数的和b的倍数的价值全加起来,公倍数染价值大的,即减去小的价值的即可

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f long long gcd(long long x,long long y){
if(y==0) return x;
else return(gcd(y,x%y));
} long long lcm(long long x,long long y){
return x*y/gcd(x,y);
} int main()
{
long long n,a,b,p,q;
while(~scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q))
{
long long lm=lcm(a,b);
printf("%lld\n",(n/a)*p+(n/b)*q-min(p,q)*(n/(lm))); }
return 0;
}

codeforces 678C. Joty and Chocolate(容斥) 2016-10-15 21:49 122人阅读 评论(0) 收藏的更多相关文章

  1. Codeforces 632D Longest Subsequence 2016-09-28 21:29 37人阅读 评论(0) 收藏

    D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. Codeforces 766D Mahmoud and a Dictionary 2017-02-21 14:03 107人阅读 评论(0) 收藏

    D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input ...

  3. hadoop容灾能力测试 分类: A1_HADOOP 2015-03-02 09:38 291人阅读 评论(0) 收藏

    实验简单来讲就是 1. put 一个600M文件,分散3个replica x 9个block 共18个blocks到4个datanode 2. 我关掉了两个datanode,使得大部分的block只在 ...

  4. Codeforces 343D Water Tree 分类: Brush Mode 2014-10-05 14:38 98人阅读 评论(0) 收藏

    Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a res ...

  5. codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces 706C Hard problem 2016-09-28 19:47 90人阅读 评论(0) 收藏

    C. Hard problem time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  7. Codeforces 768A Oath of the Night's Watch 2017-02-21 22:13 39人阅读 评论(0) 收藏

    A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. Codeforces 766C Mahmoud and a Message 2017-02-21 13:57 62人阅读 评论(0) 收藏

    C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. CodeForces 678C Joty and Chocolate

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

随机推荐

  1. Python 列表表达式 ,迭代器(1)

    python 环境 3.5 1.列表: s = []; for i in s: i = handleFunction(i); s.append(i) .列表 s=[handleFunction(i) ...

  2. gff/gtf格式

    1)gff3及gtf2简介 一个物种的基因组测序完成后,需要对这些数据进行解读,首先要先找到这些序列中转录起始位点.基因.外显子.内含子等组成元件在染色体中的位置信息(即注释)后才能再进行深入的分析. ...

  3. HTML的标签简介

    1.标签的简介: <html>与</html>之间的文本描述网页<head>与</head>之间的标签用于定义文档的头部,他是所有的头部的文件<b ...

  4. mysql服务器设置其他电脑访问

    解决pc.b想访问pc.a上的mysql而访问不了的问题. 第一步:先在navicat的tools里面选择console 第二步:输入下面的信息: '; 其中wp是登陆数据库的用户名,IP地址是允许访 ...

  5. Control(拆点+最大流)

    Control http://acm.hdu.edu.cn/showproblem.php?pid=4289 Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  6. Robotium原理初步--Android自动化测试学习历程

    章节:自动化基础篇——Robotium原理初步(第四讲) 主要讲解内容与笔记: 一.基于控件 1.spinner——下拉菜单 2.TabHost——左右滑动选择菜单,类似电话本 3.Gallery—— ...

  7. c++泛型模板

    模板是C++支持参数化多态的工具,使用模板可以使用户为类或者函数声明一种一般模式,使得类中的某些数据成员或者成员函数的参数.返回值取得任意类型. 模板是一种对类型进行参数化的工具: 通常有两种形式:函 ...

  8. [leetcode]250. Count Univalue Subtrees统计节点值相同的子树

    Given a binary tree, count the number of uni-value subtrees. A Uni-value subtree means all nodes of ...

  9. 14-n皇后

    /*题目内容: 国际象棋中的皇后可以沿着水平线,垂直线,或者斜线前进,吃掉遇到的所有棋子,如果棋盘上有八个皇后,则这八个皇后如何相安无事的放置在棋盘上,1970年与1971年, E.W.Dijkstr ...

  10. 表单数据转换成json格式数据

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...