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.

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
一个简单的容斥,我们先算a再算b,再求能被a和b一起整除的,然后算出单独被a,b整除的,一起整除的我们选最大的去乘
复制代码
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include<algorithm>
 5 using namespace std;
 6 int main()
 7 {
 8     long long n,a,b,p,q;
 9     long long ans1,ans2,ans3,ans4,ans5;
10     cin>>n>>a>>b>>p>>q;
11     ans1=n/a;ans2=n/b;ans3=a/__gcd(a,b)*b;ans4=n/ans3;
12     cout<<(ans1-ans4)*p+(ans2-ans4)*q+ans4*max(p,q)<<endl;
13     return 0;
14 }
复制代码

 

posted @   樱花落舞  阅读(205)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示