CodeForces 678C Joty and Chocolate
简单题。
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<queue> #include<map> #include<stack> using namespace std; long long n,a,b,p,q; long long gcd(long long a,long long b) { if(b==0) return a; return gcd(b,a%b); } int main() { scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q); long long num1,num2,num3; num1=n/a; num2=n/b; long long GCD=gcd(a,b); long long LCM=a*b/GCD; num3=n/LCM; long long ans=(num1-num3)*p+(num2-num3)*q+num3*max(p,q); printf("%lld\n",ans); return 0; }