Educational Codeforces Round 13 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 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整除的,一起整除的我们选最大的去乘
#include <iostream>
#include <stdio.h>
#include <string.h>
#include<algorithm>
using namespace std;
int main()
{
long long n,a,b,p,q;
long long ans1,ans2,ans3,ans4,ans5;
cin>>n>>a>>b>>p>>q;
ans1=n/a;ans2=n/b;ans3=a/__gcd(a,b)*b;ans4=n/ans3;
cout<<(ans1-ans4)*p+(ans2-ans4)*q+ans4*max(p,q)<<endl;
return ;
}
Educational Codeforces Round 13 C的更多相关文章
- Educational Codeforces Round 13 D:Iterated Linear Function(数论)
http://codeforces.com/contest/678/problem/D D. Iterated Linear Function Consider a linear function f ...
- Educational Codeforces Round 13 D. Iterated Linear Function (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/678/D 简单的矩阵快速幂模版题 矩阵是这样的: #include <bits/stdc++.h&g ...
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...
- Educational Codeforces Round 13 D. Iterated Linear Function 水题
D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...
- Educational Codeforces Round 13 C. Joty and Chocolate 水题
C. Joty and Chocolate 题目连接: http://www.codeforces.com/contest/678/problem/C Description Little Joty ...
- Educational Codeforces Round 13 B. The Same Calendar 水题
B. The Same Calendar 题目连接: http://www.codeforces.com/contest/678/problem/B Description The girl Tayl ...
- Educational Codeforces Round 13 A. Johny Likes Numbers 水题
A. Johny Likes Numbers 题目连接: http://www.codeforces.com/contest/678/problem/A Description Johny likes ...
- Educational Codeforces Round 13 A、B、C、D
A. Johny Likes Numbers time limit per test 0.5 seconds memory limit per test 256 megabytes input sta ...
- Educational Codeforces Round 13
http://codeforces.com/contest/678 A:水题 #include<bits/stdc++.h> #define fi first #define se sec ...
- Educational Codeforces Round 13 A
Description Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x gr ...
随机推荐
- 在IDEA 中用maven创建web项目
安装Maven 下载安装 去maven官网下载最新版. 解压到安装目录. 配置 右键桌面的计算机图标,属性–>高级系统设置–>环境变量,添加M2_HOME的环境变量,然后将该变量加入的PA ...
- sizeof总结
1.sizeof常用总结 ①与strlen比较 strlen 计算字符串的字符数,以"\0"为结束判断,但不统计结束符. sizeof 计算数据(数组.变量.类型. ...
- 使用Javascript Ajax 通信操作JSON数据 [下]
上一篇文章我们获得后台数据库的数据后转换成json格式然后返回到前台,但只是返回的一位数组,这次我们返回二维和三维数组和对象. 前台代码shizhan.html: <!DOCTYPE html& ...
- sql如何选取两个数据表中的值
一.直接在要选择的数据前面加上数据表的名字就行了 SELECT po.OrderID, p.LastName, p.FirstName FROM Persons AS p, Product_Order ...
- vue 的全局拦截器
使用拦截器 你可以截取请求或响应在被 then 或者 catch 处理之前 mounted:function(){ Vue.http.inserceptors.push(function(resque ...
- C++面向对象类的实例题目十一
题目描述: 写一个程序计算三角形,正方形和圆形3种图形的面积 程序代码: #include<iostream> #include<cmath> #define PAI 3.14 ...
- Angular18 RXJS
1 RX 全称是 Reactive Extensions,它是微软开发并维护的基于 Reactive Programming 范式实现的一套工具库集合:RX结合了观察者模式.迭代器模式.函数式编程来管 ...
- webfrom 母版页
ASP.NET中母版页作用 一是提高代码的复用(把相同的代码抽出来) 二是使整个网站保持一致的风格和样式. 母版页存在就一定要有内容页的存在,否则母版页的存在就没有了意义. .master 一.添加母 ...
- xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at:
今天更新了一下mac系统,然后发现 idea的svn插件不能用了,有的报 有的报 is not under version 经查找需要做如下处理,打开终端,安装xcode: xcode-selec ...
- MySQL update select组合
update t_news inner join (select readCount from t_news t2 where t2.id=1) t1 set t_news.readCount = t ...