codeforces 678C C. Joty and Chocolate(水题)
题目链接:
1 second
256 megabytes
standard input
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 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.
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的倍数给p个巧克力,b的倍数q个巧克力,即是a又是b的倍数都可以,那么[1,n]一共可以得到多少巧克力;
- 思路:
- 跟容斥定理差不多,求一个最小公倍数,就好了;
- AC代码:
- //#include <bits/stdc++.h>
- #include <iostream>
- #include <queue>
- #include <cmath>
- #include <map>
- #include <cstring>
- #include <algorithm>
- #include <cstdio>
- using namespace std;
- #define Riep(n) for(int i=1;i<=n;i++)
- #define Riop(n) for(int i=0;i<n;i++)
- #define Rjep(n) for(int j=1;j<=n;j++)
- #define Rjop(n) for(int j=0;j<n;j++)
- #define mst(ss,b) memset(ss,b,sizeof(ss));
- typedef unsigned long long uLL;
- typedef long long LL;
- const LL mod=1e9+;
- const double PI=acos(-1.0);
- const int inf=0x3f3f3f3f;
- const int N=1e6+;
- template<class T> void read(T&num) {
- char CH; bool F=false;
- for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
- for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
- F && (num=-num);
- }
- int stk[], tp;
- template<class T> inline void print(T p) {
- if(!p) { puts(""); return; }
- while(p) stk[++ tp] = p%, p/=;
- while(tp) putchar(stk[tp--] + '');
- putchar('\n');
- }
- LL n,a,b,p,q;
- LL gcd(LL x,LL y)
- {
- if(y==)return x;
- return gcd(y,x%y);
- }
- LL lcm(LL x,LL y)
- {
- LL temp=gcd(x,y);
- return x/temp*y;
- }
- int main()
- {
- read(n);
- read(a);
- read(b);
- read(p);read(q);
- LL ans=n/a*p+n/b*q-n/lcm(a,b)*min(p,q);
- cout<<ans<<"\n";
- return ;
- }
codeforces 678C C. Joty and Chocolate(水题)的更多相关文章
- 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 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- Codeforces - 1194B - Yet Another Crosses Problem - 水题
https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...
随机推荐
- 微信内置浏览器图片查看方式的原生实现(非jssdk)
对于非公众平台网页,想调起图片预览组件,就跟公众号文章一样的图片阅读方式,实现起来是比较简单的,官方也提供了jssdk来做这个.详见 http://mp.weixin.qq.com/wiki/7/aa ...
- jQuery(一)delegate() 方法
定义和用法 delegate() 方法为指定的元素(属于被选元素的子元素)添加一个或多个事件处理程序,并规定当这些事件发生时运行的函数. 使用 delegate() 方法的事件处理程序适用于当前或未来 ...
- css 文字超出变 ... 点点点
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
- Mysql的存储过程(以Mysql为例进行讲解)
我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储 在数据库中,用户通过指定存 ...
- cdoj 15 Kastenlauf dfs
Kastenlauf Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/3 De ...
- pjsip视频通信开发(上层应用)之EditText重写
我们经常使用手机的打电话功能,当我们按键盘的时候,有一个地方显示我们按键的内容,当我们的手点击那个地方的时候,并没有弹出软件盘,所以我们再有数字键盘的时候,要屏蔽系统的软件盘. 我们分析一下,软件盘弹 ...
- little's law(律特法则)
参考:https://en.wikipedia.org/wiki/Little%27s_law(周末看一下) 最近在做性能压力测试,开始时,压力压不上去,参考: N = X * E[T] ,N就是你的 ...
- Android 新浪微博代码
新浪微博开发 [代码] android Weibo weibo=new Weibo(); weibo.setUserId("sdhjob@hotmail.com"); weibo. ...
- [Angular 2] ElementRef, @ViewChild & Renderer
ElementRef: In Angular2 Doc, it suggest to "avoid" using ElementRef. It access DOM directl ...
- [MEAN+ Webstrom] First API -- 2.Debug Node.js RESTful application
Using WebStrom can easily debug the Node applcation. For example, we have an Node+Express applicatio ...