#include <iostream>
#include <algorithm>
using namespace std;
long long f(long long a){//1-a的和
long long sum=(a+1)*a/2;
return sum;
}
int main()
{
int n,a,b;
cin>>n>>a>>b;
long long ans;
long long sum,sum_a,sum_b,lcm,sum_ab;
sum=f(n);
sum_a=f(n/a)*a;
sum_b=f(n/b)*b;
lcm=(a*b)/__gcd(a,b);//求a,b的最小公倍数
sum_ab=f(n/lcm)*lcm;
ans=sum-sum_a-sum_b;
if(lcm<=n) ans+=sum_ab;
cout<<ans;
return 0;
}
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
long long num, nu;
long long gcd(long long a, long long b)
{
return a % b ? gcd(b, a % b) : b;
}
long long sum(long long x, long long y)
{
return y*(x+y*x)/2;
}
int main()
{
long long n, a, b, ans = 0;
scanf("%lld%lld%lld", &n, &a, &b);
long long bei = a * b / gcd(a, b);
ans = n * (1 + n) / 2;
num = n/a;
nu = n/b;
ans -= sum(a, num);
ans -= sum(b, nu);
for (int i = 1; i <= n; i++)
{
if (i * bei > n)
break;
ans += (i * bei);
}
printf("%lld", ans);
}
做学校oj第二种终于过了。。