678 C. Joty and Chocolate

Problem Link

<Source Code>

#include<stdio.h>

int gcd(long long int n1,long long int n2)
{
return (n2!=0)?gcd(n2,n1%n2):n1;
}
long long lcm(long long a,long long b)
{
    return (a/gcd(a,b))*b;
}
int main()
{
long long n,a,b,p,q,ans=0;
scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
ans+=(n/a)*p;
ans+=(n/b)*q;
ans-=(n/lcm(a,b))*(p>q?q:p);
printf("%lld\n",ans);
}

 

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s