CF678C.Joty and Chocolate

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

小乔蒂有一项任务需要完成。她有一排编号从 11 到 nn 的 nn 块瓷砖,需按一种特殊模式进行涂色。

  • 若某块未涂色瓷砖的编号能被 aa 整除,则应将其涂成红色;
  • 若某块未涂色瓷砖的编号能被 bb 整除,则应将其涂成蓝色。

因此,编号同时能被 aa 和 bb 整除的瓷砖,可选择涂成红色或蓝色。

涂色完成后,每块红色瓷砖可为她赢得 pp 颗巧克力,每块蓝色瓷砖可为她赢得 qq 颗巧克力。

注意:她可以按任意顺序对瓷砖进行涂色。

给定上述信息,请计算乔蒂最多能获得多少颗巧克力。

输入格式

The only line contains five integers n, a, b, p and q (1 ≤ n, a, b, p, q ≤ 109).

唯一一行包含五个整数 nn、aa、bb、pp 和 qq(1 ≤ n, a, b, p, q ≤ 1091 ≤ n, a, b, p, q ≤ 10^9)。

输出格式

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.

输出唯一的整数 ss —— Joty 能获得的巧克力的最大数量。

注意:答案可能非常大,因此应使用 64 位整数类型来存储。在 C++ 中可使用 long long 整数类型,在 Java 中可使用 long 整数类型。

输入输出样例

  • 输入#1

    5 2 3 12 15

    输出#1

    39
  • 输入#2

    20 2 3 3 5

    输出#2

    51

输入解题思路,AI测评打分。不知道怎么写?

首页