链接:http://acm.hust.edu.cn/vjudge/problem/401744/origin
题目:
题意:共有从1到n个数字1.2.3.4.3.....n,遇到a的倍数可以领p个巧克力,遇到b的倍数可以领q个巧克力,遇到既是a,又是b的倍数的领哪个都可以,问最后最多可以拿到多少巧克力。
分析:纯数学计算,只要保证重复之处的取pq的最大值就好。-
题解:
题目:
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.
题意:共有从1到n个数字1.2.3.4.3.....n,遇到a的倍数可以领p个巧克力,遇到b的倍数可以领q个巧克力,遇到既是a,又是b的倍数的领哪个都可以,问最后最多可以拿到多少巧克力。
分析:纯数学计算,只要保证重复之处的取pq的最大值就好。-
题解:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
__int64 gcd(__int64 a,__int64 b)
{
return (b)?gcd(b,a%b):a;
}
__int64 gd(__int64 a,__int64 b)
{
return a*b/gcd(a,b);
}
int main()
{
//freopen("in.txt","r",stdin);
__int64 n,a,b,p,q;
while(~scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q))
{
__int64 ans=0;
__int64 na,nb,nab,ab;
if(p<q)
{
swap(a,b);
swap(p,q);
}
ab=gd(a,b);
na=n/a;
nb=n/b;
nab=n/ab;
nb-=nab;
ans=p*na+q*nb;
printf("%I64d\n",ans);
}
return 0;
}