A frog is initially at position $$$0$$$ on the number line. The frog has two positive integers $$$a$$$ and $$$b$$$. From a position $$$k$$$, it can either jump to position $$$k+a$$$ or $$$k-b$$$.Let $$$f(x)$$$ be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval $$$[0, x]$$$. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from $$$0$$$.Given an integer $$$m$$$, find $$$\sum_{i=0}^{m} f(i)$$$. That is, find the sum of all $$$f(i)$$$ for $$$i$$$ from $$$0$$$ to $$$m$$$.

The first line contains three integers $$$m, a, b$$$ ($$$1 \leq m \leq 10^9, 1 \leq a,b \leq 10^5$$$).

Print a single integer, the desired sum.

NoteIn the first example, we must find $$$f(0)+f(1)+\ldots+f(7)$$$. We have $$$f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8$$$. The sum of these values is $$$19$$$.In the second example, we have $$$f(i) = i+1$$$, so we want to find $$$\sum_{i=0}^{10^9} i+1$$$.In the third example, the frog can't make any jumps in any case.

#include <bits/stdc++.h>
using namespace std;
const int Maxn=400005;
long long m,a,b,c,x,y,now,maxi,ans;
long long mini[Maxn];
bool vis[Maxn];
long long gcd(long long x,long long y)
{
	return x==0?y:gcd(y%x,x);
}
void exgcd(long long a,long long b,long long &X,long long &Y)
{
    if(b==0)
        X=1,Y=0;
    else
    {
        exgcd(b,a%b,X,Y);
        long long tmp=X;
        X=Y;
        Y=tmp-a/b*Y;
    }
}
int main()
{
//	freopen("D.in","r",stdin);
	scanf("%lld%lld%lld",&m,&a,&b);
	c=gcd(a,b);
	exgcd(a/c,b/c,x,y);
	while(x<=0) x+=b/c,y-=a/c;
	y*=-1;
	while(x+y)
	{
		if(now>=b&&y) now-=b,y--;
		else now+=a,x--;
		maxi=max(maxi,now);
	}
	queue <int> Qu;
	Qu.push(0);
	memset(mini,0x3f,sizeof(long long[2*maxi+1]));
	mini[0]=0;
	while(!Qu.empty())
	{
		int u=Qu.front();
		vis[u]=false;
		Qu.pop();
		if(u+a<=2*maxi&&max(u+a,mini[u])<mini[u+a])
		{
			mini[u+a]=max(u+a,mini[u]);
			if(!vis[u+a])
				Qu.push(u+a),vis[u+a]=true;
		}
		if(u-b>=0&&mini[u]<mini[u-b])
		{
			mini[u-b]=mini[u];
			if(!vis[u-b])
				Qu.push(u-b),vis[u-b]=true;
		}
	}
	for(int i=0;i<=maxi;i++)
		ans+=max(0LL,m-mini[i]+1);
	if(m<=maxi)
	{
		printf("%lld",ans);
		return 0;
	}
	long long beg=maxi+c-maxi%c,en=(m/c)*c,ele=(en-beg)/c+1;
	ans+=(m+1)*ele-(beg+en)*ele/2;
	printf("%lld",ans);
	return 0;
}

#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define v vector
#define ALL(x) x.begin(),x.end()
#define rALL(x) x.rbegin(),x.rend()
#define mp make_pair
#define fi first
#define se second
#define endl '\n'

const ll mod = 1e9 + 7;
const ld PI = acos(-1.0);

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ll m, a, b, GCD, aa, bb;
	cin >> m >> a >> b;
	GCD = __gcd(a, b);
	aa = a/GCD, bb = b/GCD;

	ll maxFound = aa;
	v<ll> pointFound = {0, aa};
	while(maxFound+1 != pointFound.size()) {
		if(pointFound.back() > bb) pointFound.push_back(pointFound.back()-bb);
		else pointFound.push_back(pointFound.back()+aa);
		maxFound = max(maxFound, pointFound.back());
	}
	maxFound *= GCD;
	for(ll i = 0; i < pointFound.size(); i ++) {
		pointFound[i] *= GCD;
	}

	v<ll> funcVal(maxFound+1, 0);
	ll ptr = 0, ans = 0;
	for(ll i = 0; i <= maxFound; i ++) {
		while((ptr < pointFound.size()) && (pointFound[ptr] <= i)) ptr ++;
		funcVal[i] = ptr;
	}
	for(ll i = 0; i <= min(m, maxFound-1); i ++) {
		ans += funcVal[i];
	}
	if(m > maxFound-1) {
		ll mm = m-maxFound+1;
		ll div = mm / GCD;
		ll rem = mm % GCD;
		ans += GCD * ((div * (2*(maxFound/GCD) + div-1)) / 2);
		ans += rem * (maxFound/GCD + div);
		ans += mm;
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;

// template {{{
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define sort_by(x, y) sort(all(x), [&](const auto& a, const auto& b) { return y; })

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;

using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;

template<typename T> void ckmin(T& a, const T& b) { a = min(a, b); }
template<typename T> void ckmax(T& a, const T& b) { a = max(a, b); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

namespace __input {
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}
using namespace __input;

namespace __output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T, bool pretty = true> void prContain(const T& x) {
        if (pretty) pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?pretty?", ":" ":"",a), fst = 0;
        if (pretty) pr("}");
    }
    template<class T> void pc(const T& x) { prContain<T, false>(x); pr("\n"); }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps();
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...);
    }
}
using namespace __output;

#define TRACE(x) x
#define __pn(x) pr(#x, " = ")
#define pd(...) __pn((__VA_ARGS__)), ps(__VA_ARGS__), cout << flush

namespace __algorithm {
    template<typename T> void dedup(vector<T>& v) {
        sort(all(v)); v.erase(unique(all(v)), v.end());
    }
    template<typename T> typename vector<T>::iterator find(vector<T>& v, const T& x) {
        auto it = lower_bound(all(v), x); return it != v.end() && *it == x ? it : v.end();
    }
    template<typename T> size_t index(vector<T>& v, const T& x) {
        auto it = find(v, x); assert(it != v.end() && *it == x); return it - v.begin();
    }
    template<typename C, typename T, typename OP> vector<T> prefixes(const C& v, T id, OP op) {
        vector<T> r(sz(v)+1, id); F0R (i, sz(v)) r[i+1] = op(r[i], v[i]); return r;
    }
    template<typename C, typename T, typename OP> vector<T> suffixes(const C& v, T id, OP op) {
        vector<T> r(sz(v)+1, id); F0Rd (i, sz(v)) r[i] = op(v[i], r[i+1]); return r;
    }
}
using namespace __algorithm;

struct monostate {
    friend istream& operator>>(istream& is, const __attribute__((unused))monostate& ms) { return is; }
    friend ostream& operator<<(ostream& os, const __attribute__((unused))monostate& ms) { return os; }
} ms;

template<typename W=monostate> struct wedge {
    int u, v, i; W w;
    wedge<W>(int _u=-1, int _v=-1, int _i=-1) : u(_u), v(_v), i(_i) {}
    int operator[](int loc) const { return u ^ v ^ loc; }
    friend void re(wedge& e) { re(e.u, e.v, e.w); --e.u, --e.v; }
    friend void pr(const wedge& e) { pr(e.u, "<-", e.w, "->", e.v); }
};

namespace __io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(15);
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
    }
}
using namespace __io;
// }}}

int main() {
    setIO();

    int M, A, B; re(M, A, B);

    const int L = min(A + B - 1, M + 1);

    vi reach(L, INT_MAX);
    reach[0] = 0;

    priority_queue<pii> pq; pq.push({0,0});
    while (!pq.empty()) {
        int maxv, cloc; tie(maxv, cloc) = pq.top(); pq.pop();
        if (reach[cloc] != (maxv *= -1)) continue;

        if (cloc >= B && maxv < reach[cloc - B]) {
            reach[cloc - B] = maxv;
            pq.push({ -maxv, cloc - B });
        }
        ckmax(maxv, cloc + A);
        if (cloc + A < L && maxv < reach[cloc + A]) {
            reach[cloc + A] = maxv;
            pq.push({ -maxv, cloc + A });
        }
    }

    ll ans = 0;
    F0R (i, L) if (reach[i] != INT_MAX) {
        ans += L - reach[i];
    }

    int g = __gcd(A, B);
    int a = L, b = M;

    while (a <= b && (a % g != 0)) { ans += a/g + 1; a++; }
    while (a <= b && (b % g != (g-1))) { ans += b/g + 1; b--; }

    if (a <= b) {
        ans += b - a + 1;
        a /= g; b /= g;
        ll tot = b * ll(b + 1) / 2
               - (a-1) * ll(a) / 2;
        ans += tot * g;
    }

    ps(ans);

}

#include <bits/stdc++.h>
using namespace std;

const int N = (int)1e6 + 50;

typedef long long ll;
bool vis[N];
queue<int> que;
int psum[N];

int n;
int a, b;
ll res = 0, cur = 0;

int main() {
    cin >> n >> a >> b;
    int lim = 4 * max(a, b) + 2;
    res = 0, cur = 0;
    vis[0] = true;

    cur ++;
    res ++;
    for(int i = 1; i <= min(n, lim); i++) {
        if(i - a >= 0 && vis[i-a]) {
            vis[i] = true;
            cur++;
            que.push(i);
        }
        else {
            res += cur;
            continue;
        }
        while(!que.empty()) {
            int v = que.front(); que.pop();
            if(v - b >= 0 && !vis[v-b]) {
                vis[v-b] = true;
                cur++;
                que.push(v-b);
            }
            if(v + a < i && !vis[v+a]) {
                vis[v+a] = true;
                cur++;
                que.push(v+a);
            }
        }
        res += cur;
    }
    int g = __gcd(a, b);
    psum[0] = 1;
    for(int i = 1; i < a; i++) psum[i] = psum[i-1] + (i % g == 0);
    assert(psum[a - 1] == a / g);
    ll t_res = 0;

    ll c_res = 0;
    if(n > lim) {
        for(int rem = 0; rem < g; rem++) {
            ll fir = (lim + 1 - rem + g - 1) / g + 1;
            ll sec = (n + 1 - rem + g - 1) / g;
            c_res += (sec + fir) * (sec - fir + 1) / 2;
        }
    }
    cout << res + c_res << endl;
}

#pragma region Include/Defines
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <queue>
#include <time.h>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef vector<pii> vpii;
typedef vector <pll> vpll;
typedef long double ld;
#define all(a) std::begin(a), std::end(a)

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

template<typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); }
template<typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); }

#ifdef _DEBUG
#define epr(...) fprintf(stderr,__VA_ARGS__)
#else
#define epr(...)
#endif
#pragma endregion

const int MAX = 4e5 + 10;
int m, a, b, gd;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

void clear() {
}

void read() {
}

int f(int n) {
	set<int> used = { 0 };
	set<int> q = { 0 };
	while (!q.empty()) {
		auto x = *q.begin();
		q.erase(q.begin());
		if (!used.count(x + a) && x + a <= n)  used.insert(x + a), q.insert(x + a);
		if (!used.count(x - b) && x - b >= 0)  used.insert(x - b), q.insert(x - b);
	}
	cerr << n << ":" << used.size() << endl;
	return used.size();
}

lli solve1() {
	lli s = 0;
	for (int i = 0; i <= m; i++) s += f(i);
	return s;
}

lli solve2() {
	lli res = 0;
	int lim = a + b, gd = gcd(a, b);
	set<int> used = { 0 };
	for (int n = 1; n < min(m + 1, lim); n++) {
		if (used.count(n - a)) {
			set<int> q = { n };
			used.insert(n);
			while (!q.empty()) {
				auto x = *q.begin();
				q.erase(q.begin());
				if (!used.count(x + a) && x + a <= n)  used.insert(x + a), q.insert(x + a);
				if (!used.count(x - b) && x - b >= 0)  used.insert(x - b), q.insert(x - b);
			}
		}
		res += used.size() - 1;
	}
	if (lim <= m) {
		int d = m - lim + 1;
		int ng = d / gd;
		int zm = lim + ng * gd;

		// prog
		if (lim < zm) {
			int a1 = lim / gd;
			int an = (zm - 1) / gd;
			lli s = 1ll * ng * (a1 + an) / 2 * gd;
			res += s;
		}

		if (zm <= m)
			res += (m - zm + 1) * (zm / gd);
	}
	return res;
}

void solve() {
	//lli res1 = solve1();
	lli res2 = solve2() + m + 1;
	//assert(res1 == res2);
	printf("%lld\n", res2);
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d%d%d", &m, &a, &b) == 3) {
		clear();
		read();
		gd = gcd(a, b);
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

const int INF = 1e9;

ll prog(ll a, ll b, ll d) {
    ll l = (b-a)/d + 1;
    if (l > 0) return (a+b)*l/2;
    else return 0;
}

ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; }

#undef int
int main() {
#define int ll
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int m,a,b; cin >> m >> a >> b;
    vi dist(a+b+a+b+10,INF);
    dist[0] = 0;
    priority_queue<pii> q; q.emplace(0,0);
    while (!q.empty()) {
        int d = -q.top().first;
        int u = q.top().second;
        q.pop();
        if (d > dist[u]) continue;
        if (u >= b && dist[u-b] > dist[u]) {
            dist[u-b] = dist[u];
            q.emplace(-dist[u], u-b);
        }
        if (u+a < si(dist) && dist[u+a] > max(u+a, dist[u])) {
            dist[u+a] = max(u+a, dist[u]);
            q.emplace(-max(u+a,dist[u]), u+a);
        }
    }

    ll ans = 0;
    int i = 0;
    while (i <= m && i < si(dist)) {
        ans += max(0LL, m+1-dist[i]);
        i++;
    }

    ll d = gcd(a,b);
    D(d);
    int from = i, to = m;
    while (from%d) ++from;
    while (to%d) --to;
    ans += prog(m+1-to,m+1-from,d);
    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define N 300009
#define ll long long
int dist[N],dis[N],vis[N];
ll f[N];
priority_queue< pair<int,int> >que;
int gcd(int u,int v)
{
	if(v==0) return u;
	int t=u,f=v;
	u=v;
	v=t%f;
	return gcd(u,v);
}
int main()
{
	int m,a,b,n;
	scanf("%d%d%d",&m,&a,&b);
	n=2*a+b;
	memset(dist,63,sizeof dist);
	dist[0]=0;
	que.push({0,0});
	while(!que.empty())
	{
		int x=que.top().second;
		vis[x]=1;
		if(x>=b && dist[x-b]>dist[x])
		{
			dist[x-b]=dist[x];
			que.push({-dist[x-b],x-b});
		}
		if(x+a<=n && dist[x+a]> max(x+a,dist[x]))
		{
			dist[x+a]=max(x+a,dist[x]);
			que.push({-dist[x+a],x+a});
		}
		while(!que.empty() && vis[que.top().second]) que.pop();
	}
	ll ans=0;
	int mn=min(m,a+b-1);
	for(int i=0;i<=mn;++i)
		ans+=max(0,mn-dist[i]+1);
	if(m>=a+b)
	{
		int s=a/gcd(a,b);
		memcpy(dis,dist,sizeof dist);
		sort(dis,dis+n);
		ll nowf=0;
		for(int i=0,p=0,tot=0;i<n;++i)
		{
			while(p!=n && dis[p]-1<=i)
			{
				++tot;
				nowf-=dis[p]-1;
				++p;
			}
			f[i]=nowf+1ll*tot*i;
		}
		for(int i=n-1;i;--i)
			f[i]-=f[i-1];
		for(int fl=a+b,fr=(m-b%a)/a*a+b%a;fl<a+a+b;++fl,++fr)
		{
			if(fr>m) fr-=a;
			int l=fl/a,r=fr/a;
			ans+=1ll*(r-l+1)*f[fl]+1ll*(r-l+1)*(r-l)/2*s;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

#ifdef LocalHost
#define _GLIBCXX_DEBUG
#endif

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cmath>

using namespace std;

typedef int64_t int64;
typedef vector<int> vi;

// BEGIN CUT
#define DBG cerr << __LINE__ << ": @" << __FUNCTION__ << "  "
#define VAR(x) #x << "=" << x << " "
#define REP(i,n) for (int i = 0; i < (n); i++)
#define REPV(i,v) for (size_t i = 0; i < v.size(); i++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define UNIQUE(x) SORT(x), x.resize(unique(ALL(x)) - x.begin())
#define pb push_back

template <class T1, class T2>
ostream& operator <<(ostream& os, const pair<T1, T2>& v) {
  os << "(" << v.first << " " << v.second << ")";
  return os;
}

template <typename T,
          typename U = typename T::value_type,
          typename = typename enable_if<!is_same<T, string>::value>::type>
ostream& operator<<(ostream& os, const T& v) {
  os << '[';
  for (const auto& it : v)
    os << it << " ";
  if (!v.empty()) os << "\b";
  os << "]";
  return os;
}
// END CUT

int a, b, cnt;
vector<bool> visited;

void go(int pos, int max) {
  visited[pos] = true;
  cnt++;
  if (pos+a <= max && !visited[pos+a]) go(pos+a, max);
  if (pos-b >= 0   && !visited[pos-b]) go(pos-b, max);
}

int64 solve(int m) {
  visited.assign(1e8, false);
  visited[0] = true;
  cnt = 1;
  int64 ans = 1; // f(0)
  for (int i = 1; i <= m; i++) {
    if (i-a >= 0 && visited[i-a])
      go(i, i);
    if (cnt == i+1) {
      ans += int64(i+m+2)*(m-i+1)/2;
      cnt = m+1;
      break;
    }
    ans += cnt;
  }
  return ans;
}

int main() {
#ifdef LocalHost
  freopen("input.txt", "rt", stdin);
#endif
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  int m;
  cin >> m >> a >> b;
  int d = __gcd(a, b);
  a /= d, b /= d;
  int64 ans = solve(m/d)*d;
  if ((m+1) % d != 0)
    ans -= int64(cnt) * ((m/d)*d+d-1-(m+1)+1);
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 9e18
#define MAXN 300005
ll n,m,a,b,x,ans,an[MAXN];bool f[MAXN];queue<int>q;
ll gcd(ll x,ll y){
    if(x%y!=0)return gcd(y,x%y);
    return y;
}
ll F(ll x){return x*(x+1)>>1;}
ll D(ll x,ll mo){return x/mo+(x%mo>0);}
ll G(ll n){return F((n+1)/x)*x+((n+1)%x)*(D(n+1,x));}
int bfs(int i){
    int ans=0;f[0]=1;
    while(!q.empty()){
        int x=q.front();
        q.pop(),ans++;
        if(x+a<=i&&!f[x+a])f[x+a]=1,q.push(x+a);
        if(x-b>=0&&!f[x-b])f[x-b]=1,q.push(x-b);
    }
    return ans;
}
int main(){
    cin>>n>>a>>b,q.push(0),an[0]=f[0]=1,bfs(0),x=gcd(a,b);
    for(int i=1;i<=max(a,b)*2;i++){
        if(i-a>=0&&f[i-a])f[i]=1,q.push(i),an[i]=an[i-1]+bfs(i);
        else an[i]=an[i-1];
    }
    if(a>b)swap(a,b);
    for(int i=0;i<min(n+1,2*b);i++)ans+=an[i];
    if(n>=2*b)ans+=G(n)-G(2*b-1);
    cout<<ans;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <set>
#include <map>
#include <list>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

/// Definitions
typedef long long        LL;
typedef unsigned long long ULL;
typedef long double      LD;
typedef unsigned int     UI;
typedef pair<int, int>   PII;
typedef vector<int>      VI;

// #define FILE
// #define PRECISION   10
#define fr          first
#define sc          second
#define mp          make_pair
#define pb          push_back
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define f(i,a,b)    for (int i = a; i < b; ++i)
#define r(i,a,b)    for (int i = a - 1; i >= b; --i)
#define loop(n)     f(_, 0, n)
/// Constants
const LL    INF64 = 1000000000000000000;
const LL    BigPrime = 252097800623;
const LD    LDINF = 1000000000000;
const LL    Mmod = 998244353;
const LL    INF = 1000000000;
const LL    Mod = 1000000007;
const LD    PI = acosl(-1.);
const LD    Eps = 10e-10;
const LL    Prime = 31;
const UI    N = 100005;
/// ----------------------------------------------------
long long m, a, b;
long long hgh[1000000];
bool visited[1000000];
priority_queue<int> pq;

LL gcd(LL a, LL b) {
	return (a == 0 ? b : gcd(b % a, a));
}

void input()
{
	cin >> m >> a >> b;
}

void solve()
{
	pq.push(0);
	for (int i = 0; i <= 400000; i++)
		hgh[i] = i;
	visited[0] = true;
	vector<int> test;
	while (!pq.empty()) {
		int cd = -pq.top();
		pq.pop();
		test.pb(cd);
		if (cd > b && !visited[cd - b]) {
			visited[cd - b] = true;
			hgh[cd - b] = max(hgh[cd], hgh[cd - b]);
			pq.push(b - cd);
		}
		if (cd + a <= 400000 && !visited[cd + a]) {
			visited[cd + a] = true;
			hgh[cd + a] = max(hgh[cd], hgh[cd + a]);
			pq.push(- (cd + a));
		}
	}

	if (m <= 400000) {
		long long ans = 0;
		for (int i = 0; i <= m; i++)
			if (hgh[i] <= m && visited[i])
				ans += (m - hgh[i] + 1);
		cout << ans << endl;
	}
	else {
		long long ans = 0;
		for (int i = 0; i <= 400000; i++)
			if (visited[i])
				ans += (m - hgh[i] + 1);

		LL d = gcd(a, b);
		LL from = 400000 / d + 1, to = m / d;
		ans += (to - from + 1) * (m + 1) - d * ((to * (to + 1) / 2) - (from * (from - 1) / 2));
		cout << ans << endl;
	}
}

int main()
{
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
#ifdef PRECISION
    cout.setf(ios::fixed);
    cout.precision(PRECISION);
#endif

    int testcases = 1;
    // scanf("%d", &testcases);
    loop(testcases) {
        input();
        //clock_t start = clock();
        solve();
        //printf("---------------------\n%.5f seconds\n---------------------\n", (clock() - start + 0.) / CLOCKS_PER_SEC);
    }

    return 0;
}

#include<bits/stdc++.h>
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d ",x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define pf2(x,y) printf("%d %d ",x,y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define pf3(x,y,z) printf("%d %d %d ",x,y,z)
#define sfc(c) scanf(" %c",&c)
#define pfc(c) printf("%c",c)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define INF 1000000008
#define LLINF ll(1e18+10)
#define ENDL puts("")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef unsigned int uint;
typedef long double ld;

template<class T>
void printVector(T begin, T end)
{
    for(auto i=begin; i!=end; i++)
    {
        cout<<*i<<' ';
    }
    cout<<endl;
}

ll readLL() {
    ll x;
    cin >> x;
    return x;
}

int readInt() {
    int x;
    cin >> x;
    return x;
}

int gcd(int a, int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}

bool u[700300];
ll cnt=1;
ll res=0;
int m,a,b;

void dfs(int v, int l, int r)
{
    u[v]=1;
    cnt++;
    if(v+a<=r)
    {
        if(!u[v+a])
        {
            dfs(v+a,l,r);
        }
    }
    if(v-b>=0)
    {
        if(!u[v-b])
        {
            dfs(v-b,l,r);
        }
    }
}

int main()
{
    /*
    freopen("caravan.in","r",stdin);
    freopen("caravan.out","w",stdout);
    /**/

    u[0]=1;

    sf3(m,a,b);
    int g=gcd(a,b);
    int i=0;
    for(i=0; i<=min(m,400000); i++)
    {
        if(i-a>=0&&u[i-a])
        {
            dfs(i,0,i);
        }
        res+=cnt;
    }
    while(i<=m&&i%g!=0)
    {
        if(i-a>=0&&u[i-a])
        {
            dfs(i,0,i);
        }
        res+=cnt;
        i++;
    }
    if(i<=m)
    {
        g=1;
        while(u[g]==0)
        {
            g++;
        }
        ll tmp=(m-i)/g;
        i+=tmp*g;
        res+=g*((ll)cnt*tmp+(ll)tmp*(tmp+1)/2);
        res+=(m-i+1)*(cnt+tmp+1);
    }

    cout<<res;

    return 0;

}

#include<bits/stdc++.h>

#define ll long long
#define INF 2147483647

bool f[6000010];
int n, a, b;
int cnt = 1;

void dfs(int cur){
    if(f[cur])
        return ;
    // printf("%d\n", cur);
    f[cur] = true;
    cnt++;
    dfs(cur + a);
    if(cur - b >= 0)
        dfs(cur - b);
}

ll get_sum(ll x, ll m){
    ll num = x / m;
    ll ans = num * (num + 1) >> 1;
    ans *= m;
    ans += (num + 1) * (x - (num * m) + 1);
    return ans;
}

int __gcd(int a, int b){
    return (b == 0) ? a : __gcd(b, a % b);
}

int main(){
    f[0] = true;
    scanf("%d %d %d", &n, &a, &b);
    memset(f, true, sizeof(f));
    ll ans = 1;
    for(int i = 1; i <= std::min(5000000, n); i++){
        if((i - a) >= 0 && f[i - a]){
            f[i] = false;
            dfs(i);
        } else
            f[i] = false;
        ans += cnt;
        // printf("f(%d) = %lld\n", i, cnt);
    }
    int gcd = __gcd(a, b);
    if(n > 5000000)
        ans += get_sum(n, gcd) - get_sum(5000000, gcd);
    printf("%lld\n", ans);
}
// ...

#include<bits/stdc++.h>
#define sz(x) (int)x.size()
#define ms(a,b) memset(a, b, sizeof(a))
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define R(i, n) FOR(i, 0, n)
#define int long long
#define pb push_back
#define all(a) (a.begin()),(a.end())
#define D(x) cout << #x << " = " << x << endl
#define input freopen("/Users/shahadat/Desktop/input.txt", "r", stdin)
#define output freopen("/Users/shahadat/Desktop/output.txt", "w", stdout)
#define valid(x,y) x>=0 && y>=0 && x<n && y<n
#define ff  first
#define ss  second

int gcd(int n1, int n2){
    if (n2 != 0) return gcd(n2, n1 % n2);
    else return n1;
}

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int INF = 1e18;
int const N = 1e6 + 10;
const int M = 210;
int const MOD = 1e9 + 7;

int fun(int n, int g){
    int m = (n / g);
    int baki = (1 + (n % g)) * m;
    int tot = g * (m *(m - 1))/2 + baki;
    return tot + n + 1;
}

int m, a, b;
int cnt = 0;
bool visit[N] = {false};
int res[N];
priority_queue<int, vector<int>, greater<int> > S;

void play(int val){
    while (S.size() > 0) {
        int top = S.top();
        if(top > val)
            break;
        S.pop();
        visit[top] = true;
        cnt++;

        if(visit[top + a] == false)  S.push(top + a);
        if(top - b > 0 && visit[top - b] == false)
            S.push(top - b);
    }
}

int32_t main(){
    cin>>m>>a>>b;

    int g = gcd(a, b);
    S.push(0);

    int ans = 0;
    for(int i = 0; i<=min(a + b, m); i++){
        if(S.top() == i || S.top() + a == i){
            play(i);
            res[i] = cnt;
        }
        //cout<<cnt<<" ";
        ans += cnt;
    }

    if(m > a + b){
        ans += fun(m, g) - fun(a + b, g);
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int f[2*N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int m,a,b;
    cin>>m>>a>>b;
    for(int i=0;i<a+b;i++)
        f[i]=-1;
    int now=0,M=0;
    while(f[now]==-1){
        f[now]=M;
        if(now>=b)
            now-=b;
        else
            now+=a;
        M=max(M,now);
    }
    ll res=0;
    for(int i=0;i<=m&&i<a+b;i++){
        if(f[i]>-1&&f[i]<=m)
            res+=m-f[i]+1;
    }
    if(a+b<=m){
        int d=__gcd(a,b);
        int n=m-m%d;//n>=a+b cause d=gcd(a,b)
        ll t=(n-a-b)/d+1;//a*x+b*y=c -> gcd|c  n,n-d,n-2d,...,n-(t-1)*d
        res+=m*t-(n*t-t*(t-1)/2*d)+t;
    }
    printf("%lld\n",res);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int a,int b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
signed main()
{
	int m,a,b;
	scanf("%lld %lld %lld",&m,&a,&b);
	int n=a,maxn=a,cnt=2,pts=0,ans=a;
	if(m<a)
	{
		printf("%lld\n",m+1);
		return 0;
	}
	while(n)
	{
		if(n>=b)
			n-=b;
		else
			n+=a;
		if(n>maxn)
		{
			if(n>m)
			{
				printf("%lld\n",ans+(m-maxn+1)*cnt);
				return 0;
			}
			ans+=(n-maxn)*cnt;
			maxn=n;
		}
		cnt++;
	}
	int g=gcd(a,b);
	if(maxn/g==m/g)
		printf("%lld\n",ans+(m-maxn+1)*(maxn/g+1));
	else
	{
		int ad=g-maxn%g;
		if(ad==g)
			ad=0;
		ans+=(maxn/g+1)*ad;
		maxn+=ad;
		int mi=m%g+1;
		if(mi==g)
			mi=0;
		ans+=(m/g+1)*mi;
		m-=mi;
		int l=maxn/g+1,r=m/g+1;
		ans+=(l+r)*(r-l+1)/2*g;
		printf("%lld\n",ans);
	}
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define li long long
#define ull unsigned long long
#define pb push_back
#define in insert
#define er erase
#define f(i,a,b) for(li i=a;i<b;++i)
#define rf(i,a,b) for(li i=a;i>=b;--i)
#define tc int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define sll set<ll>
#define vll vector<ll>
#define vull vector<ull>
#define vc vector<char>
#define vst vector<string>
#define bs bitset
#define mpir make_pair
#define ff first
#define ss second
#define pii pair<int ,int>
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define lb lower_bound
#define ub upper_bound
#define mxe max_element
#define mne min_element
#define nl "\n"
#define sp " "
#define INF ((0x3f3f3f3f))
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ok order_of_key
#define fo find_by_order

//ll md=1000000007;
ll md = 998244353;

ll pw(ll a, ll b){
    ll c=1, m=a;
    while(b){
        if(b&1)c=(c*m);
        m=(m*m);b/=2;
    }
    return c;
}
ll pwmd(ll a, ll b){
    ll c=1, m=a;
    while(b){
        if(b&1)c=(c*m)%md;
        m=(m*m)%md;b/=2;
    }
    return c;
}
ll mmi(ll a)
{
    ll inverse = pwmd(a, md-2); //
    return inverse ;
}

 bool prime(ll n)
 {
     if(n==2)return true;
     if(!(n%2))
         return false;
     else{
         for(ll i=3;i<n;i+=2)
         {
             if(!(n%i))
                 return false;
         }
     }
return true;
 }
 ll mult(li a,li b)
 {
     return ((a%md)*(b%md))%md;
 }
 ll add(li a,li b)
 {return (a+b)%md;}
 ll sub(li a,li b)
 {return (a+md-(b)%md)%md;}
 ll my_ceil(ll n,ll m)
 {
     return n/m+((n%m)?1:0);
 }
ll m,a,b;
int main()
{
fast;
//ll tests;cin>>tests;while(tests--)

    cin>>m>>a>>b;
    //if(m==1000000000){cout<<500000001500000001;exit(0);}
    ll ans = 0;
    queue<pll>q;vll mark(a+b+1);
    q.push({0,0});
    while(!q.empty()){
        pll p = q.front();mark[p.ff]=1;
        q.pop();
        ans+=(m-p.ss+1);
        if(p.ff+a<=min(m,a+b)&&!mark[p.ff+a])mark[p.ff+a]=1,q.push({p.ff+a,max(p.ff+a,p.ss)});
        if(p.ff-b>=0&&!mark[p.ff-b])mark[p.ff-b]=1,q.push({p.ff-b,max(p.ff-b,p.ss)});
    }
    ll gc = gcd(a,b);ll p =1;
    ll n = m/gc-(a+b)/gc;
    if(n>0)
    ans+=(n*(2*(m-gc*(m/gc)+1)+(n-1)*gc))/2;
cout<<ans<<nl;
return 0;
}

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

// #undef DEBUG
// #define DEBUG
// DEBUG {{{
#include <array>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>
template < int n, class... T >
typename std::enable_if< (n >= sizeof...(T)) >::type __output_tuple(
    std::ostream &, std::tuple< T... > const &) {}
template < int n, class... T >
typename std::enable_if< (n < sizeof...(T)) >::type __output_tuple(
    std::ostream &os, std::tuple< T... > const &t) {
  os << (n == 0 ? "" : ", ") << std::get< n >(t);
  __output_tuple< n + 1 >(os, t);
}
template < class... T >
std::ostream &operator<<(std::ostream &os, std::tuple< T... > const &t) {
  os << "(";
  __output_tuple< 0 >(os, t);
  os << ")";
  return os;
}
template < class T, class U >
std::ostream &operator<<(std::ostream &os, std::pair< T, U > const &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template < class T >
std::ostream &operator<<(std::ostream &os, const std::stack< T > &a) {
  os << "{";
  for(auto tmp = a; tmp.size(); tmp.pop())
    os << (a.size() == tmp.size() ? "" : ", ") << tmp.top();
  os << "}";
  return os;
}
template < class T, class Container, class Compare >
std::ostream &operator<<(std::ostream &os,
    std::priority_queue< T, Container, Compare > a) {
  os << "{ (top) ";
  while(a.size()) os << a.top() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
template < class T, class Container >
std::ostream &operator<<(std::ostream &os, std::queue< T, Container > a) {
  os << "{ ";
  while(a.size()) os << a.front() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
#ifdef DEBUG
#if !defined(DEBUG_OUT)
// #define DEBUG_OUT std::cerr
#endif
#define dump(...)                                                                \
  [&]() {                                                                        \
    auto __debug_tap = std::make_tuple(__VA_ARGS__);                             \
    DEBUG_OUT << "[" << __LINE__ << "] " << #__VA_ARGS__ << " = " << __debug_tap \
    << std::endl;                                                      \
  }()
template < class T >
inline void dump2D(T &d, size_t sizey, size_t sizex) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << "\t";
    for(size_t j = 0; j < sizex; j++)
      DEBUG_OUT << d[i][j] << (j + 1 == sizex ? "" : "\t");
    DEBUG_OUT << std::endl;
  }
}
template < class T >
inline void dump1D(T &d, size_t sizey) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << d[i] << (i + 1 == sizey ? "" : " ");
  }
  DEBUG_OUT << std::endl;
}
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        os << "{";
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : ", ") << *ite;
        os << "}";
        return os;
      }
#else
#define dump(...) (42)
#define dump2D(...) (42)
#define dump1D(...) (42)
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : " ") << *ite;
        return os;
      }
#endif
// }}}

/// --- math {{{ ///
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d;
  return b == 0 ? (x = a < 0 ? -1 : 1, y = 0, a < 0 ? -a : a)
    : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
}
ll modinv(ll a, ll mod) {
  ll x, y;
  extgcd(a, mod, x, y);
  if(x < 0) x += mod;
  return x;
}
ll modpow(ll a, ll b, ll mod) {
  ll r = 1;
  a %= mod;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
/// }}}--- ///

// LazySegmentTree( size [, initial] )
// LazySegmentTree( <data> )
/// --- LazySegmentTree {{{ ///
#include <cassert>
#include <initializer_list>
#include <iostream>
#include <vector>
template < class M_act >
struct LazySegmentTree {
public:
  using Monoid = typename M_act::Monoid;
  using X = typename Monoid::T;
  using M = typename M_act::M;

private:
  size_t n;
  int h;
  vector< X > data;
  vector< M > lazy;
  vector< size_t > nodeLength;
  // call before use data[i]
  void eval(size_t i) {
    if(lazy[i] == M_act::identity()) return;
    data[i] = M_act::actInto(lazy[i], nodeLength[i], data[i]);
    if(i < n) {
      lazy[i * 2] = M_act::op(lazy[i], lazy[i * 2]);
      lazy[i * 2 + 1] = M_act::op(lazy[i], lazy[i * 2 + 1]);
    }
    lazy[i] = M_act::identity();
  }
  // call before use seg[i] = data[i + n]
  void evalDown(size_t i) {
    i += n;
    for(int j = h - 1; j >= 0; j--) eval(i >> j);
  }
  // call after touch seg[i] = data[i + n]
  void propUp(size_t i) {
    i += n;
    while(i >>= 1)
      eval(i * 2), eval(i * 2 + 1), data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
  }

public:
  LazySegmentTree() : n(0) {}
  LazySegmentTree(size_t n, X initial = Monoid::identity()) : n(n) {
    if(n > 0) {
      h = 1;
      while(1u << h < n) h++;
      data.resize(2 * n, initial);
      lazy.resize(2 * n, M_act::identity());
      nodeLength.resize(2 * n, 1);
      for(size_t i = n - 1; i > 0; i--) // fill from deep
        data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]),
          nodeLength[i] = nodeLength[i * 2] + nodeLength[i * 2 + 1];
    }
  }
  template < class InputIter, class = typename iterator_traits< InputIter >::value_type >
    LazySegmentTree(InputIter first, InputIter last)
    : LazySegmentTree(distance(first, last)) {
      if(n > 0) {
        copy(first, last, begin(data) + n);
        for(size_t i = n - 1; i > 0; i--) // fill from deep
          data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
      }
    }
  LazySegmentTree(vector< X > v) : LazySegmentTree(v.begin(), v.end()) {}
  LazySegmentTree(initializer_list< X > v) : LazySegmentTree(v.begin(), v.end()) {}
  void act(int l, int r, const M &m) {
    if(l < 0) l = 0;
    if(l >= r) return;
    if(r > (int) n) r = n;
    evalDown(l);
    evalDown(r - 1);
    int tl = l, tr = r;
    for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) eval(l), lazy[l] = m, eval(l), l++;
      if(r & 1) --r, eval(r), lazy[r] = m, eval(r);
    }
    propUp(tl);
    propUp(tr - 1);
  }
  void set(size_t i, const X &x) {
    assert(i < n);
    evalDown(i);
    data[i + n] = x;
    propUp(i);
  }
  X get(size_t i) {
    assert(i < n);
    evalDown(i);
    return data[i + n];
  }
  X fold(int l, int r) {
    if(l < 0) l = 0;
    if(l >= r) return Monoid::identity();
    if(r > (int) n) r = n;
    evalDown(l);
    evalDown(r - 1);
    X tmpL = Monoid::identity(), tmpR = Monoid::identity();
    for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) eval(l), tmpL = Monoid::op(tmpL, data[l]), l++;
      if(r & 1) --r, eval(r), tmpR = Monoid::op(data[r], tmpR);
    }
    return Monoid::op(tmpL, tmpR);
  }
  int size() { return n; }
  inline void dum(int r = -1) {
#ifdef DEBUG
    if(r < 0) r = n;
    DEBUG_OUT << "{";
    for(int i = 0; i < min(r, (int) n); i++) DEBUG_OUT << (i ? ", " : "") << get(i);
    DEBUG_OUT << "}" << endl;
#endif
  }
};

/// }}}--- ///

/// --- Monoid examples {{{ ///
constexpr long long inf_monoid = 1e18 + 100;
#include <algorithm>
struct Nothing {
  using T = char;
  using Monoid = Nothing;
  using M = T;
  static constexpr T op(const T &, const T &) { return T(); }
  static constexpr T identity() { return T(); }
  template < class X >
    static constexpr X actInto(const M &, long long, const X &x) {
      return x;
    }
};

template < class U = long long >
struct RangeMin {
  using T = U;
  static T op(const T &a, const T &b) { return std::min< T >(a, b); }
  static constexpr T identity() { return T(inf_monoid); }
};

template < class U = long long >
struct RangeMax {
  using T = U;
  static T op(const T &a, const T &b) { return std::max< T >(a, b); }
  static constexpr T identity() { return T(-inf_monoid); }
};

template < class U = long long >
struct RangeSum {
  using T = U;
  static T op(const T &a, const T &b) { return a + b; }
  static constexpr T identity() { return T(0); }
};

template < class U >
struct RangeProd {
  using T = U;
  static T op(const T &a, const T &b) { return a * b; }
  static constexpr T identity() { return T(1); }
};

template < class U = long long >
struct RangeOr {
  using T = U;
  static T op(const T &a, const T &b) { return a | b; }
  static constexpr T identity() { return T(0); }
};

#include <bitset>

template < class U = long long >
struct RangeAnd {
  using T = U;
  static T op(const T &a, const T &b) { return a & b; }
  static constexpr T identity() { return T(-1); }
};

template < size_t N >
struct RangeAnd< std::bitset< N > > {
  using T = std::bitset< N >;
  static T op(const T &a, const T &b) { return a & b; }
  static constexpr T identity() { return std::bitset< N >().set(); }
};

/// }}}--- ///

/// --- M_act examples {{{ ///
template < class U = long long, class V = U >
struct RangeMinAdd {
  using X = U;
  using M = V;
  using Monoid = RangeMin< U >;
  static M op(const M &a, const M &b) { return a + b; }
  static constexpr M identity() { return 0; }
  static X actInto(const M &m, long long, const X &x) { return m + x; }
};

template < class U = long long, class V = U >
struct RangeMaxAdd {
  using X = U;
  using M = V;
  using Monoid = RangeMax< U >;
  static M op(const M &a, const M &b) { return a + b; }
  static constexpr M identity() { return 0; }
  static X actInto(const M &m, long long, const X &x) { return m + x; }
};

template < class U = long long, class V = U >
struct RangeMinSet {
  using M = U;
  using Monoid = RangeMin< U >;
  using X = typename Monoid::T;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return M(-inf_monoid); }
  static X actInto(const M &m, long long, const X &x) { return m == identity() ? x : m; }
};

template < class U = long long, class V = U >
struct RangeMaxSet {
  using M = U;
  using Monoid = RangeMax< U >;
  using X = typename Monoid::T;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return M(-inf_monoid); }
  static X actInto(const M &m, long long, const X &x) { return m == identity() ? x : m; }
};

template < class U = long long, class V = U >
struct RangeSumAdd {
  using X = U;
  using M = V;
  using Monoid = RangeSum< U >;
  static M op(const M &a, const M &b) { return a + b; }
  static constexpr M identity() { return 0; }
  static X actInto(const M &m, long long n, const X &x) { return m * n + x; }
};

template < class U = long long, class V = U >
struct RangeSumSet {
  using X = U;
  using M = V;
  using Monoid = RangeSum< U >;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return M(-inf_monoid); }
  static X actInto(const M &m, long long n, const X &x) {
    return m == identity() ? x : m * n;
  }
};

template < class U, class V = U >
struct RangeProdMul {
  using X = U;
  using M = V;
  using Monoid = RangeProd< U >;
  static M mpow(M a, long long b) {
    X r(1);
    while(b) {
      if(b & 1) r = r * a;
      a = a * a;
      b >>= 1;
    }
    return r;
  }
  static M op(const M &a, const M &b) { return a * b; }
  static constexpr M identity() { return M(1); }
  static X actInto(const M &m, long long n, const X &x) { return x * mpow(m, n); }
};

template < class U, class V = U >
struct RangeProdSet {
  using X = U;
  using M = V;
  using Monoid = RangeProd< U >;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return V::unused; }
  static X actInto(const M &m, long long n, const X &) {
    if(m == identity()) return;
    return RangeProdMul< U, V >::mpow(m, n);
  }
};

template < class U = long long, class V = U >
struct RangeOr2 {
  using X = U;
  using M = V;
  using Monoid = RangeOr< U >;
  static M op(const M &a, const M &b) { return a | b; }
  static constexpr M identity() { return M(0); }
  static X actInto(const M &m, long long, const X &x) { return m | x; }
};

template < class U = long long, class V = U >
struct RangeAnd2 {
  using X = U;
  using M = V;
  using Monoid = RangeAnd< U >;
  static M op(const M &a, const M &b) { return a & b; }
  static constexpr M identity() { return M(-1); }
  static X actInto(const M &m, long long, const X &x) { return m & x; }
};

template < class U, size_t N >
struct RangeAnd2< U, std::bitset< N > > {
  using X = U;
  using M = std::bitset< N >;
  using Monoid = RangeAnd< U >;
  static M op(const M &a, const M &b) { return a & b; }
  static constexpr M identity() { return std::bitset< N >().set(); }
  static X actInto(const M &m, long long, const X &x) { return m & x; }
};
/// }}}--- ///

using Seg = LazySegmentTree< RangeSumAdd<> >;

ll rangesum(ll a, ll b) {
  // ll sum = 0;
  // for(ll i = a; i <= b; i++) sum += i;
  // return sum;
  return (b - a + 1) * (b - a + 2) / 2 + (b - a + 1) * (a - 1);
}

int m, a, b;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> m >> a >> b;
  vector<int> v(a, -1);
  v[0] = 0;

  int now = 0;
  while(true) {
    int nxt = ((now - b) % a + a) % a;
    if(nxt == 0) break;
    int h = now + max(b - now, 0) / a * a;
    while(h < b) h += a;
    v[nxt] = max(v[now], h);
    now = nxt;
  }

  vector<pair<int, int>> w;
  for(int i = 0; i < a; i++) w.emplace_back(v[i], i);
  w.emplace_back(m + 1, 0);
  sort(begin(w), end(w));

  ll L = 0;
  ll ans = 0;

  Seg seg(a);

  auto calc = [&](ll L, ll R, ll g, ll num) {
    return (R - L + 1) * (g - 1) * num + seg.fold(L % a, R % a + 1);
  };

  // dump(rangesum(0, 10));
  // dump(rangesum(2, 10));
  // dump(rangesum(7, 10));

  int c = 0;
  for(int i = 0; i <= a; i++) {
    if(w[i].first == -1) continue;
    ll R = w[i].first - 1;
    R = min<ll>(R, m);
    // dump(seg.fold(0, 1));
    dump(L, R);
    if(L <= R) {
      seg.dum();
      dump(i);
      ll lg = L / a + 1;
      ll rg = R / a + 1;
      dump(lg, rg);
      if(lg == rg) {
        ans += calc(L, R, lg, c);
      } else {
        if(lg + 1 <= rg - 1) ans += rangesum(lg + 1 - 1, rg - 1 - 1) * a * c + seg.fold(0, a) * (rg - lg - 2 + 1);
        dump(ans);
        ans += calc(L, lg * a - 1, lg, c);
        dump(ans);
        ans += calc(rg * a - a, R, rg, c);
        dump(ans);
      }
      L = R + 1;
    }
    if(L == m + 1) break;
    seg.act(w[i].second, a, 1);
    c++;
  }

  cout << ans << endl;

  return 0;
}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
long long gcd(long long a,long long b)
{
	if (a%b==0) return b;
	return gcd(b,a%b);
}
long long add(long long k,long long x)
{
	long long m=(k+1)/x;
	return (k+1)*m-(x*m*(m+1)/2);
}
int main()
{
	long long n,a,b;
	scanf("%lld %lld %lld",&n,&a,&b);
	long long x=gcd(a,b);
	long long ma1=0;
	long long ma=max(2*a,2*b);
	long long z=ma;
	long long si=0;
	long long ans=0;
	if (a==b)
	{
		printf("%lld",add(n,a));
		return 0;
	}
	if (a>n)
	{
		printf("%lld",n+1);
		return 0;
	}
	do
	{
		if (si>=b)
		{
			int t=si/b;
			si-=t*b;
			if (si==0) t--;
			ans+=t*(z-ma1+1);
			}
		else
		if (si+a<=ma1)
		{
			int t=(ma1-si)/a;
			si+=t*a;
			ans+=t*(z-ma1+1);
		}
		else
		{
			int t=(b-si+a-1)/a;
			{
				si+=a*t;
				ma1=si;
				ans+=t*(z-si+1);
			}
		}
//		printf("%d ",ans);
//		printf("%d \n",si);
		if (si==0||n<ma1) break;
	}
	while (1);
	ans=0;si=0; z=min(n,ma1); ma=ma1; ma1=0;

//	printf("%d",ma);
	do
	{
		if (si>=b)
		{
			int t=si/b;
			si-=t*b;
			if (si==0) t--;
			ans+=t*(z-ma1+1);
			}
		else
		if (si+a<=ma1)
		{
			int t=(ma1-si)/a;
			si+=t*a;
			ans+=t*(z-ma1+1);
		}
		else
		{
			int t=(b-si+a-1)/a;
			if (si+t*a>n)
			{
				for (si=si+a;si<=n;si+=a)
				{
					ans+=(z-si+1);
				}
				break;
			}
			else
			{

				ans+=(z-si+1)*t-(t*(t+1)/2)*a;
				si+=a*t;
				ma1=si;
			}
		}
//		printf("%d ",ans);
//		printf("%d \n",si);
		if (si==0||n<ma1) break;
	}
	while (1);
	ans+=n+1;
	if (n>ma) ans+=add(n,x)-add(ma,x);
	printf("%lld",ans);
	return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
#define rep(i, a, b) for (register int i=(a); i<=(b); ++i)
#define per(i, a, b) for (register int i=(a); i>=(b); --i)
using namespace std;
const int N=200005; int vis[N], x, y, ans;

inline int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}

int gcd(int a, int b){return b?gcd(b, a%b):a;}

signed main()
{
	int m=read(), a=read(), b=read();
	memset(vis, -1, sizeof(vis));
	while(1)
	{
		vis[x]=y;
		if (x<b) x+=a; else x-=b;
		if (!x) break; y=max(y, x);
	}
	rep(i, 0, a+b-1)
		if(~vis[i]) ans+=max(0ll, m-vis[i]+1);
	if (m>=a+b)
	{
		int c=m-a-b+1;
		int g=gcd(a, b), len=c/g*g;
		int first=c-len, last=c, cnt=(last-first)/g+1;
		ans+=(last+first)*cnt/2;
	}
	printf("%lld\n", ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define LL long long
#define INF (LL)(0x3f3f3f3f)*(LL)0x3f3f3f3f
#define MAXN 300005

LL n,m;
LL a,b,x;
LL ans = 0;
LL an[MAXN];
bool f[MAXN];
queue<int>q;

LL gcd(LL x,LL y) {
	if(x%y != 0) return gcd(y,x%y);
	return y;
}

LL orz(LL x) {
	return x*(x+1)>>1;
}

LL sqz(LL x,LL mo)
{
	if(x % mo == 0) return x/mo;
	else return x/mo+1;
}

LL stO(LL n) {
//	cout<<n<<":"<<(n+1)/x<<" "<<sqz(n+1,x)<<" "<<orz((n+1)%x)<<"!!!\n";
//	cout<<orz((n+1)/x)*x + ((n+1)%x)*(sqz(n+1,x))<<"\n";
	return orz((n+1)/x)*x + ((n+1)%x)*(sqz(n+1,x));
}

int bfs(int i)
{
	int ans = 0;
	//q.push(0);
	f[0] = 1;

	while(!q.empty()) {
		int x = q.front();
	//	cout<<x<<"?!\n";
		q.pop();
		ans ++;
		if(x+a <= i && !f[x+a]) {
			f[x+a] = 1;
			q.push(x+a);
		}
		if(x-b >= 0 && !f[x-b]) {
			f[x-b] = 1;
			q.push(x-b);
		}
	}
	return ans;
}

signed main()
{
	cin >> n >> a >> b;

	q.push(0);
	an[0] = 1;
	f[0] = 1;
	bfs(0);
	for(int i = 1; i <= max(a,b)*2; i ++) {
		if(i-a >= 0 &&f[i-a]) {
			f[i] = 1;
			q.push(i);
		//	cout<<i<<"?QAQ\n";
			an[i] = an[i-1]+bfs(i);
		} else {
			an[i] = an[i-1];
		}
	//	cout<<i<<" "<<an[i]<<"\n";
	}

	x = gcd(a,b);
	if(a < b)
	{
		int ls = 0;
		for(int i = 0; i < min(n+1,2*b); i ++) {
			ans += an[i];
		}

		if(n >= 2*b)
			ans += stO(n) - stO(2*b-1);
	} else {
		swap(a,b);

		for(int i = 0; i < min(n+1,2*b); i ++) {
			ans += an[i];
		}
		//cout<<ans<<"\n";
//		cout<<stO(n)<<" "<<stO(2*b-1)<<"\n";
		if(n >= 2*b)
			ans += stO(n) - stO(2*b-1);
	}
	cout<<ans;
	return 0;
 }
 /*1000000000 1 100000
 */

#include<bits/stdc++.h>
#define db(x) cerr<<#x<<" = "<<x<<endl;
using namespace std;
int f[200005];
int m,a,b;
struct node{
	int val,pos;
};
node make_node(int pos,int val){
	node ans;
	ans.val=val;
	ans.pos=pos;
	return ans;
}
bool operator > (node x,node y){
	return x.val>y.val;
}
priority_queue<node,vector<node>,greater<node> >pq;
int main(){
	scanf("%d%d%d",&m,&a,&b);
	long long ans=0;
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	pq.push(make_node(0,0));
	while(!pq.empty()){
		node now=pq.top();
		pq.pop();
		if(f[now.pos]!=now.val)continue;
		if(now.pos-b>=0){
			if(f[now.pos-b]>f[now.pos]){
				f[now.pos-b]=f[now.pos];
				pq.push(make_node(now.pos-b,f[now.pos-b]));
			}
		}
		if(now.pos+a<=a+b){
			if(f[now.pos+a]>max(f[now.pos],now.pos+a)){
				f[now.pos+a]=max(f[now.pos],now.pos+a);
				pq.push(make_node(now.pos+a,f[now.pos+a]));
			}
		}
	}
	for(register int i=0,j=0;i<=m;++i,++j){
		if(j==a)j=0;
		ans+=max(0,m-max(i,f[j])+1);
	}
	printf("%I64d",ans);
	return 0;
}

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	long long m, a, b;
	cin >> m >> a >> b;
	const long long bruteless = 300000;
	long long res = 0;
	long long d = __gcd(a, b);
	long long first = -1;
	for (long long i = bruteless + 1; i <= m; i++) {
		if (i % d == 0) {
			first = i;
			break;
		}
	}
	long long numOf = (m/d) - (bruteless/d);
	if (first != -1) {
		res = (((m - first + 1) + (m - first - ((numOf - 1) * d) + 1)) * numOf) / 2;
	}

	long long firstApp[bruteless+1];
	for (int i = 1; i <= bruteless; i++) {
		firstApp[i] = -1;
	}
	firstApp[0] = 0;
	queue<int> done;
	done.push(0);
	while (!done.empty()) {
		int temp = done.front();
		done.pop();
		if (temp + a <= bruteless) {
			if (firstApp[temp+a] == -1) {
				firstApp[temp+a] = max(firstApp[temp], temp+a);
				done.push(temp+a);
			}
			else {
				if (firstApp[temp + a] > max(firstApp[temp], temp+a)) {
					done.push(temp+a);
				}
				firstApp[temp+a] = min(max(firstApp[temp], temp+a), firstApp[temp+a]);
			}
		}
		if (temp - b >= 0) {
			if (firstApp[temp-b] == -1) {
				firstApp[temp-b] = firstApp[temp];
				done.push(temp-b);
			}
			else {
				if (firstApp[temp - b] > firstApp[temp]) {
					done.push(temp-b);
				}
				firstApp[temp-b] = min(firstApp[temp], firstApp[temp-b]);
			}
		}
	}
	for (int i = 0; i <= min(m, bruteless); i++) {
		if (firstApp[i] != -1 && firstApp[i] <= m) {
			res += (long long)(m - firstApp[i] + 1);
		}
	}

	cout << res;
}

#include <cctype>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <stack>
#include <fstream>
#include <bitset>
#include <ctime>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ft first
#define sd second
#define all(x) (x).begin(),(x).end()
#define mfor(i,b,e) for(int i=b;i<e;i++)

vector<int> v;
long long  a, b,h=2;
long long req(int n) {
	long long sum=1;
	if (n + a < h && v[n+a]==0) {
		v[n + a] = 1;
		sum += req(a + n);
	}
	if (n - b > 0 && v[n - b] == 0) {
		v[n - b] = 1;
		sum += req(n - b);
	}
	return sum;
}
long long gcd(long long a, long long b) {
	return a ? gcd(b % a, a) : b;
}
int main()
{
	long long m,ans=2,k=1,z,p,asa;
	cin >> m >> a >> b;
	if (m > a + b) {
		z = gcd(a, b);
		p = m;
		ans = 2 * z;
		asa = m - ((m - z + 1) / z) * z - z + 1;
		m = (m - z + 1) / z;
		a /= z;
		b /= z;
		if (a == 1) {
			ans = ((m + 1) * (m + 2) / 2) * z;
			ans += asa * (p / z + 1);
			cout << ans << endl;
			return 0;
		}
		v.resize((a + b + 1) * 10);
		v[0] = 1;
		while (h <= m) {
			if (h >= a && v[h - a] == 1) {
				v[h] = 1;
				k += req(h);
			}
			ans += k * z;
			h++;
			if (k == h)
				break;
		}
		//h = min(h, m);
		ans += ((m + 1) * (m + 2) / 2 - h * (h + 1) / 2) * z;
		ans += asa * (p / z + 1);
		cout << ans << endl;
	}
	else {
		if (a == 1) {
			cout << (m + 1) * (m + 2) / 2 << endl;
			return 0;
		}
		v.resize((a + b + 1) * 100);
		v[0] = 1;
		while (h <= m) {
			if (h >= a && v[h - a] == 1) {
				v[h] = 1;
				k += req(h);
			}
			ans += k;
			h++;
			if (k == h)
				break;
		}
		//h = min(h, m);
		ans += (m + 1) * (m + 2) / 2 - h * (h + 1) / 2;
		cout << ans << endl;
	}
}

#include<bits/stdc++.h>
#define ll long long
#define N 200100
using namespace std;

ll n,a,b,f,g,ans,num[N],qz[N],top;

inline ll qh(ll u,ll v){return (u+v)*(v-u+1)/2;}
inline ll gcd(ll u,ll v)
{
    for(;v;)
    {
	u%=v;
	swap(u,v);
    }
    return u;
}

int main()
{
    ll i,j,p,q,t;
    cin>>n>>a>>b;
    g=gcd(a,b);
    num[top=1]=0;
    for(i=0;;)
    {
	i+=a;
	num[++top]=i;
	for(;i>=b;)
	{
	    i-=b;
	    if(!i) break;
	    num[++top]=i;
	}
	if(!i) break;
    }
//    for(i=1;i<=top;i++) cout<<num[i]<<" ";puts("");
    t=0;
    for(i=1;i<=top;i++)
    {
	t=max(t,num[i]);
	qz[t]++;
    }
    t=0;
    for(i=0;i<=min(a+b-1,n);i++)
    {
	t+=qz[i];
	ans+=t;
    }
    if(n<a+b)
    {
	cout<<ans;
	return 0;
    }
//    cout<<" "<<ans<<endl;
    if((a+b)/g==n/g)
    {
	for(i=n;i<=a+b;i++)
	    ans+=i/g+1;
	cout<<ans;
	return 0;
    }
    p=((a+b)/g+1)*g;ans+=(p-(a+b))*((a+b)/g+1);
    q=n/g*g-1;ans+=(n-q)*(n/g+1);
//    cout<<p<<" "<<q<<" "<<ans<<endl;
    ans+=qh(p/g+1,q/g+1)*g;
    cout<<ans;
}

#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double

#define pb push_back
#define ins insert
#define er erase

#define f(i, a, b) for (int i = a; i < b; ++i)
#define rf(i, a, b) for (int i = a; i >= b; --i)
#define mem(a, b) memset(a, b, sizeof(a))

#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vb vector<bool>
#define vst vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define all(v) v.begin(), v.end()
#define lb lower_bound
#define ub upper_bound
#define mxe max_element
#define mne min_element

#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())

#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second

#define bs bitset
#define bpc(a) __builtin_popcount(a)

#define mii map<int, int>
#define mll map<ll, ll>
#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>

#define si set<int>
#define sll set<ll>
#define usi unordered_set<int>
#define usll unordered_set<ll>
#define spii set<pii>
#define spll set<pll>

#define pqi priority_queue<int>
#define pqll priority_queue<ll>

#define dbg(a, st, end)                   \
    f(i, st, end + 1) cerr << a[i] << sp; \
    cerr << nl;
#define pnt(a, st, end)                   \
    f(i, st, end + 1) cout << a[i] << sp; \
    cout << nl;
#define dbgc(a)          \
    for (auto y : a)     \
        cerr << y << sp; \
    cerr << nl;
#define dbgm(a)                            \
    for (auto y : a)                       \
        cerr << y.ff << "," << y.ss << sp; \
    cerr << nl;

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)

#define nl "\n"
#define sp " "

using namespace std;
using namespace std::chrono;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>
#define ok order_of_key
#define fo find_by_order

//ll md = 1000000007;
ll md = 998244353;

ll pw(ll a, ll b)
{
    ll c = 1, m = a;
    while (b)
    {
        if (b & 1)
            c = (c * m);
        m = (m * m);
        b /= 2;
    }
    return c;
}

ll pwmd(ll a, ll b)
{
    ll c = 1, m = a;
    while (b)
    {
        if (b & 1)
            c = (c * m) % md;
        m = (m * m) % md;
        b /= 2;
    }
    return c;
}

ll modinv(ll n)
{
    return pwmd(n, md - 2);
}

ll my_ceil(ll a, ll b)
{
    if (a % b == 0)
        return a / b;
    return a / b + 1;
}

ll nc2(ll n)
{
    return (1ll * n * (n - 1)) / 2;
}

int my_log(ll n, int b)
{
    ll i = 1;
    int ans = 0;
    while (1)
    {
        if (i > n / b)
            break;
        i *= b;
        ans++;
    }
    return ans;
}

inline int nc()
{
    static char buf[100000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}
inline int read()
{
    int ret = 0;
    bool f = 0;
    char ch = nc();
    while (ch > '9' || ch < '0')
        f ^= ch == '-', ch = nc();
    while (ch <= '9' && ch >= '0')
        ret = ret * 10 + ch - '0', ch = nc();
    return f ? -ret : ret;
}

ll min(ll a, ll b)
{
    return (a < b ? a : b);
}

ll max(ll a, ll b)
{
    return a + b - min(a, b);
}

inline ll add(ll a, ll b) { return (((a >= md) ? a % md : a) + ((b >= md) ? b % md : b) + md) % md; }
inline ll subt(ll a, ll b) { return (a - b + md) % md; }
inline ll mult(ll a, ll b) { return (1ll * ((a >= md) ? a % md : a) * ((b >= md) ? b % md : b)) % md; }

inline bool kthbit(ll n, int k) { return (n >> k) & 1; }
inline ll setkthbit(ll n, int k) { return n | (1ll << k); }
inline ll unsetkthbit(ll n, int k) { return n & ~(1ll << k); }
inline ll flipkthbit(ll n, int k) { return n ^ (1ll << k); }

//LET'S PLAY THE GAME!!

int main()
{
    fast;

    ll l, r, e, h, k, n;
    ll x, q, c, m;

    string s, t;

    auto start = high_resolution_clock::now();

    int tcnt = 0;
    int tests = 1;
    //pre();
    //cin >> tests;

    while (tests--)
    {
        //cout << "Case #" << ++tcnt << ": ";
        ll a, b;
        cin >> m >> a >> b;
        ll st[a + b];
        mem(st, -1);
        h = gcd(a, b);
        st[0] = 0;
        if (a > b)
        {
            ll cur = a, mxcur = a;
            while (1)
            {
                if (st[cur] != -1)
                    break;
                mxcur = max(mxcur, cur);
                for (int i = cur; i > 0; i -= b)
                    st[i] = max(mxcur, i);
                cur = cur % b + a;
            }
        }
        else
        {
            for (int i = 0; i < a + b; i += a)
                st[i] = i;
            ll cur = a * (b / a);
            if (cur < b)
                cur += a;
            ll mxcur = cur;
            while (1)
            {
                if (st[cur - b] != -1)
                    break;
                mxcur = max(mxcur, cur);
                e = 0;
                for (int i = cur - b; i < a + b; i += a)
                    st[i] = max(mxcur, i), e = i;
                cur = e;
            }
        }
        ll ans = 0;
        /* for(int i=0;i<a+b;i+=571){
            cerr<<st[i]<<sp;if(i%10==9)cerr<<nl;
        } */
        f(i, 0, min(a + b, m + 1)) if (st[i] != -1 && st[i] <= m) ans += (m - st[i] + 1);
        //dbgc(st);
        //cerr<<ans<<nl;
        if (a + b > m)
        {
            cout << ans;
            return 0;
        }
        l = h * ((a + b) / h);
        if (l < a + b)
            l += h;
        c = h * (m / h);
        e = (c - l) / h + 1;
        r = m - c + 1;
        ans += (e * (2 * r + (e - 1) * h)) / 2;
        cout << ans;
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cerr << "Time taken: "
         << duration.count() / 1000000.0 << "seconds" << nl;
    return 0;
}

// AND THE GAME IS OVER !!

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required

// using namespace __gnu_pbds;
using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) {for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " | " << H; debug_out(T...);}
// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;  // ordered_set <long long> s; // order_of_key(value)

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second

const long long N = 800100;
long long n, k, m, a, b, f[N], lim, use[N], ans;
set <long long> waiting;
vector <long long> v[N];

void dfs(long long node) {
	f[lim]++;
	use[node] = 1;

	for(auto i : v[node])
		if(i <= lim && !use[i])
			dfs(i);
		else if(i > lim)
			waiting.insert(i);
}

long long sum(long long l, long long r, long long g) {
	long long R = r / g;
	R *= g;
	long long nr = (R - l) / g;
	// dbg(l, r, g, R, nr);
	// dbg(nr);
	// long long ans = 0;
	long long ans = g * ((nr + 1) * nr / 2 + nr * (l / g)) ;
	// dbg(ans);
	for(long long i = R; i <= r; i++)
		ans += i / g + 1;
	// dbg(ans);
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false);

	cin >> m >> a >> b;
	// long long g = __gcd(a, b);
	// dbg(a);
	// dbg(b);
	// a /= g;
	// b /= g;
	// m /= g;

	// pt orice raspuns > (a + b) rezultatul este f(a + b) + (m - a - b);
	long long X = 2 * (a + b);

	for(long long i = 0; i <= X + b; i++)
		v[i].push_back(i + a);

	for(long long i = b; i <= X + a + b; i++)
		v[i].push_back(i - b);

	f[0] = 1;
	use[0] = 1;
	waiting.insert(a);

	for(lim = 1; lim <= X + a + b; lim++) {
		f[lim] = f[lim - 1];

		// dbg(waiting);

		if(*waiting.begin() == lim) {
			waiting.erase(waiting.begin());
			dfs(lim);
		}
	}

	for(long long i = 0; i <= min(m, X + a + b - 1); i++)
		ans += f[i];

	// dbg_v(f, X + X);

	// dbg(sum(4, 10, 1));
	// return 0;

	// dbg(ans);
	// dbg(X + a + b);
	// dbg((X + X + 1) * (X + X + 2) / 2);

	long long cnt = m - X - a - b;
	// dbg(ans, "asd");
	if(cnt >= 0) {
		// dbg(cnt);
		ans += sum(X + a + b, m, __gcd(a, b));
	}
	cout << ans << '\n';
}

#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll sum(ll n) {
    if (n <= 0)
        return 0;
    return n * (n + 1) / 2;
}

ll sum_range(ll l, ll r) {
    if (l > r)
        return 0;
    return sum(r) - sum(l - 1);
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll m, a, b;
    cin >> m >> a >> b;

    vector<bool> seen(a + 1);
    seen[0] = true;
    int seen_mod_a = 1;

    ll d = gcd(a, b);
    ll f = 1;
    ll s = 0;

    priority_queue<int, vector<int>, greater<int>> pq;
    pq.emplace(a);

    ll x_prev = 0;

    while (!pq.empty()) {
        ll x_curr = pq.top();
        pq.pop();

        if (x_curr > m) {
            s += (m - x_prev + 1) * f;
            x_prev = m;
            break;
        }

        if (seen_mod_a == a / d)
            break;

        if (x_curr > x_prev) {
            s += (x_curr - x_prev) * f;
            x_prev = x_curr;
        }

        while ((int) seen.size() <= x_curr)
            seen.resize(2 * seen.size());

        for (ll y = x_curr; y >= 0; y -= b) {
            if (seen[y])
                continue;
            seen[y] = true;
            if (y < a)
                seen_mod_a++;
            f++;
            pq.push(y + a);
        }
    }

    if (m > x_prev) {
        s += m - x_prev + 1;
        for (ll i = x_prev; i / d == x_prev / d; i++)
            s += i / d;
        for (ll i = m; i / d == m / d; i--)
            s += i / d;
        s += d * sum_range(x_prev / d + 1, m / d - 1);
    }

    cout << s << endl;
}

#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 5000200;
const long long mod = 998244353;

using namespace std;

int cnt;
long long res;
bool used[N];
int mx, a, b;
vector < int > v;

void dfs(int x)
{
        v.push_back(x);
        while(!v.empty()){
                x = v.back();
                v.pop_back();
                if(used[x]){
                        continue;
                }
                used[x] = 1;
                cnt += 1;
                if(x + a <= mx){
                        v.push_back(x + a);
                }
                if(x - b >= 0){
                        v.push_back(x - b);
                }
        }
}

long long solve(long long n, long long g)
{
        long long res = (n % g + 1) * (n / g + 1);
        n /= g;
        return res + n * (n + 1) / 2 * g;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        long long n;
        cin >> n >> a >> b;
        used[0] = 1;
        cnt = 1;
        int m = min((long long)5e6, n), g = __gcd(a, b);
        for(int i = 0; i <= m; i++){
                mx = i;
                if(i - a >= 0 && used[i - a]){
                        dfs(i);
                }
                res += cnt;
        }
        if(n > m){
                assert(used[g]);
        }
        res += solve(n, g) - solve(m, g);
        cout << res << "\n";
}

#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD  998244353//1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef  long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef ll ValType;
template<typename  T> void maxtt(T& t1, T t2) {
    t1=max(t1,t2);
}
template<typename  T> void mintt(T& t1, T t2) {
    t1=min(t1,t2);
}
#define MAX 135

bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="URDL";//"RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    assert(y>=0);
    x+=y; if (x>=mod) x-=mod;
    assert(x>=0 && x<mod);
}
void et(int x=-1) {
    printf("%d\n", x); exit(0);
}
ll fastPow(ll x, ll y, int mod=MOD) {
    ll ans = 1;
    while(y>0) {
        if(y&1) ans = (x * ans)%mod;
        x = x*x%mod;
        y>>=1;
    }
    return ans;
}
ll gcd1(ll x, ll y) {
    return y?gcd1(y,x%y):x;
}

void fmain(int tid) {
    int a,b;
    scanf("%d%d%d", &m,&a,&b);
    vector<int> h(b+a+5,inf);
    h[0]=0;
    priority_queue<pii> q;
    q.push({0,0});
    while(!q.empty()) {
        pii cur = q.top(); q.pop();
        int x=-cur.first, i=cur.second;
        if (x>h[i]) continue;
        if (i>b && x<h[i-b]) {
            h[i-b]=x; q.push({-x, i-b});
        }
        if(i<=b && h[i+a] > max(i+a, h[i])) {
            h[i+a]=max(i+a, h[i]); q.push({-h[i+a],i+a});
        }
    }
    ll ans=0;
    for(int i=0;i<=min(m,a+b);i++) ans += max(0, m-h[i]+1);
    if(m>a+b) {
        ll g=gcd1(a,b);
        ll lo=(a+b+1)/g+((a+b+1)%g!=0);
        ll hi=m/g;
        if(lo<=hi) {
             hi*=g; lo*=g;
            ll k=(hi-lo)/g;
            ll z=m-hi+1;
            ans += (z+z+k*g)*(k+1)/2;
        }
    }
    printf("%lld\n", ans);
}
int main() {
    int t=1;
//    scanf("%d", &t);
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}

/*
    Author:  raghav.blacklist1
*/

#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define	ln(a,b)		((a==(b-1))?'\n':' ')
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair

using namespace std;

int main(void){

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	ll m,a,b;
	cin>>m>>a>>b;

	ll temp=__gcd(a,b);
	ll pre[a+b-temp+1]={0};

	queue<pii> q;
	q.push({0,0});

	while(!q.empty()){

		auto tmp=q.front();
		q.pop();

		if(tmp.F+a<=(a+b-temp) && pre[tmp.F+a]==0){

			pre[tmp.F+a]=max(tmp.F+a,tmp.S);
			q.push({tmp.F+a,max(tmp.F+a,tmp.S)});
		}

		if(tmp.F-b>0 && pre[tmp.F-b]==0){

			pre[tmp.F-b]=max(tmp.F-b,tmp.S);
			q.push({tmp.F-b,max(tmp.F-b,tmp.S)});
		}
	}

	//rep(i,0,a+b-temp)	cout<<pre[i]<<ln(i,a+b-temp);

	ll sm[a+b-temp+1]={0};
	rep(i,0,a+b-temp+1)	if(i==0 || pre[i]!=0)	sm[pre[i]]++;
	rep(i,1,a+b-temp+1)	sm[i]+=sm[i-1];

	ll ans=0;
	rep(i,0,min(m,a+b-temp)+1)	ans+=sm[i];

	if(m>(a+b-temp)){

		ll st=a+b-temp+1;
		ll en=m;

		if((en-st+1)<=4*temp)	rep(i,st,en+1)	ans+=(i/temp + 1);
		else{

			ll st1=((st+temp-1)/temp)*temp;
			ans+=((st1-st)*(st/temp + 1));
			ll en1=(en/temp)*temp;
			ans+=((en-en1+1)*(en/temp+1));

			ll b1=en/temp;
			ll a1=((st+temp-1)/temp);

			ans+=(temp)*((b1-a1)*a1 + (b1-a1)*(b1-a1+1)/2);
		}
	}

	cout<<ans<<endl;

	return 0;
}

	#include <bits/stdc++.h>
	using namespace std;

	#define MOD 1000000007
	#define INF 0x3f3f3f3f //numeric_limits<int>::max()
	#define INFLL 0x3f3f3f3f3f3f3f3fLL //numeric_limits<ll>::max()
	#define mp make_pair
	#define mt make_tuple
	#define getT(T, p) get<p>(T)
	#define pb push_back
	#define st first
	#define nd second
	#define contOnes __builtin_popcountl
	#define powDI __builtin_powi
	#define sz(v) int(v.size())
	#define ver(x) if(debug) {cout << #x << " is " << x << endl;}
	#define endLine if(debug) {cout << endl;}
	#define __ << " " <<
	//cuidado parametro duplicados
	#define all(X) (X).begin(), (X).end()
	#define logLow(X) (X <= 0 ? 0 : 31 - __builtin_clz(X))
	#define logUpper(X) (X <= 1 ? 0 : 32 - __builtin_clz(X-1))
	#define pow2(X) ((X)*(X))
	#define unico(X) X.erase(unique((X).begin(), (X).end()), (X).end())

	typedef long long ll;
	typedef pair<int,int> ii;
	typedef pair<int,ii> iii;
	typedef vector<int> vi;
	typedef vector<vi> vvi;
	typedef vector<ii> vii;
	typedef vector<vii> vvii;
	typedef vector<iii> viii;
	typedef vector<ll> vll;

	const double EPS = 1e-8;
	//const double PI = atan(1.0)*4;
	const double PI = 2*acos(0.0);
	inline int cmp(double x, double y = 0, double tol = EPS) {
		return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
	}

	int main(void) {
		int m2, a, b;
		cin >> m2 >> a >> b;
		int g = __gcd(a, b);
		a /= g;
		b /= g;
		int m = m2/g;
		vi vet(a+b);
		vet[0] = 1;
		vet[a] = 2;
		int vis = 1;
		ll cont = 1;
		for (int i = 1; i < min(a + b, m+1); ++i){
			if(vet[i] == 2){
				vi pi(1, i);
				while(!pi.empty()){
					int u = pi.back();
					pi.pop_back();
					if(u < 0 || u >= a+b || vet[u] == 1) continue;
					if(u > i){
						vet[u] = 2;
						continue;
					}
					vet[i] = 1;
					vis++;
					pi.pb(u + a);
					pi.pb(u - b);
				}
			}
			cont += vis;
		}
		if(m >= a + b) {
			cont += (m + 1ll)*(m + 2)/2 - (a + b + 1ll)*(a + b)/2;
			vis = m + 1;
		}
		cont *= g;

		cout << cont - (ll(m)*g + g - 1 - m2)*vis << endl;
		return 0;
	}

#include<bits/stdc++.h>
using namespace std;
long long n,m,a,b;
long long res = 0;
bool used[200002] = {0};
long long t[200002] = {0};
long long ans = 0;
void dfs(long long nw){
    if(nw<0||nw>m) return;
    if(used[nw]) return;
    long long orz = res;
    res = max(res,nw);
    t[nw] = min(res,t[nw]);
    used[nw] = 1;
    dfs(nw-b);
    dfs(nw+a);
    res = orz;
}
int main(){
    cin >> n >> a >> b;
    m = max(a,b)*2;
    if(n<=m) m = n;
    for(int i = 1;i<=m;i++)
        t[i] = m+1;
    dfs(0);
    for(int i = 0;i<=m;i++)
        ans+=1ll*(m-t[i]+1);
    if(n!=m){
        ans+=(n-m);
        int dzd = __gcd(a,b);
        int c1 = n%dzd+1;
        int c2 = n/dzd;
        int c3 = m%dzd+1;
        int c4 = m/dzd;
        n = n-c1;
        m = m-c3;
        ans+=1ll*(((n/dzd)*(n+1)/2)-((m/dzd)*(m+1)/2));
        ans+=1ll*(c1*c2-c3*c4);
    }
    cout << ans;
    return 0;
}

#include<iostream>
#include<cstring>
#define MAX 200005
#define ll long long
using namespace std;
ll ans,m,a,b,d,check[MAX],s[MAX],cnt;
ll gcd(ll x,ll y){
	return y==0?x:gcd(y,x%y);
}
int main(){
	cin>>m>>a>>b;
	d=gcd(a,b);
	ans=(m/d+1)*(m/d)*d/2+(m%d+1)*(m/d+1);
//	cout<<ans<<endl;
	for(cnt=0;!check[s[cnt]];){
		check[s[cnt++]]=1;
		s[cnt]=s[cnt-1]>=b?s[cnt-1]-b:s[cnt-1]+a;
	}
	for(int i=0,tot=0;i<a+b&&i<=m;i++){
		ans-=i/d+1;
		while(tot<cnt&&s[tot]<=i)tot++;
		ans+=tot;
	}
	cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

int gcd(int x, int y){
	return y == 0 ? x : gcd(y, x % y);
}

int rec[N << 1], cnt[N << 1];

int main(){
	int m, a, b, now, tot, maxx, _gcd, rem;
	long long ans;
	cin >> m >> a >> b;
	_gcd = gcd(a, b);
	a /= _gcd;
	b /= _gcd;
	now = 0; tot = 1; maxx = 0;
	while (tot < a + b){
		if (now >= b) now -= b;
		else{
			now += a;
			maxx = max(maxx, now);
		}
		rec[now] = maxx;
		tot++;
	}
	for (int i = 0; i <= a + b - 1; i++) cnt[rec[i]]++;
	for (int i = 1; i <= a + b - 1; i++) cnt[i] += cnt[i - 1];
	ans = 0;
	rem = m % _gcd;
	m /= _gcd;
	if (m >= a + b - 1){
		for (int i = 0; i <= a + b - 2; i++) ans += cnt[i] * _gcd;
		ans -= (m + 1) * (_gcd - rem - 1);
		ans += 1LL * ((a + b) + m + 1) * (m - (a + b) + 2) / 2 * _gcd;
	}
	else{
		for (int i = 0; i <= m; i++) ans += cnt[i] * _gcd;
		ans -= cnt[m] * (_gcd - rem - 1);
	}
	cout << ans << '\n';
	return 0;
}

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define orta ((l+r)>>1)
#define INF 1000000009
#define mod 1000000007
#define ppair(x)  "(" << x.first << ", " << x.second << ") "
#define bas(x) #x << ": " << x << " "
#define prarr(x, n); cerr << #x << ": "; for(int qsd = 0; qsd < n; qsd++) cerr << x[qsd] << " "; cerr << "\n";
#define prarrv(x); cerr << #x << ": "; for(int qsd = 0; qsd < (int)x.size(); qsd++) cerr << x[qsd] << " "; cerr << "\n";
using namespace std;
typedef long long ll;

ll n, a, b;
ll minarr[100001];

ll getmin(ll i){
	return minarr[i];
}

int main(){
	//freopen("stl.gir", "r", stdin);

	cin >> n >> a >> b;

	for (int i = 0; i <= a; i++) minarr[i] = -1;
	minarr[0] = 0;
	ll k = a;
	ll cur = 0;
	while (k != 0){
		cur = max(cur, k);
		if (k <= a) minarr[k] = cur;
		if (k >= b) k-= b;
		else k+= a;
	}

	ll ans = 0;
	for (int i = 0; i < a; i++){

		ll minn = getmin(i);
		ll alt = (minn-minn%a)/a + (minn%a > i);
		ll ustmin = minn + (((i-minn%a)%a)+a)%a;
		ll ustmax = n-(((-i+n%a)%a)+a)%a;
		ll tmp = ustmin;
		ustmin = n-ustmax+1;
		ustmax = n-tmp+1;
		//cout << bas(i) << bas(minn) << bas(alt) << bas(ustmin) << bas(ustmax) << endl;
		if (minn == -1) continue;
		if (minn > n) continue;
		ans += alt*(n-minn+1);
		if (ustmin <= ustmax) ans += (ustmin+ustmax)*((ustmax-ustmin)/a+1)/2;
	}
	cout << ans << endl;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
const int mod = 1000000007;
const vi mods = {998244353,1000000007,1000000009};
const ll inf = 3e18;
const double pi = acos(-1.0);
const double eps = 0.0000001;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define trav(a,x) for(auto&a:x)
#define all(x) begin(x),end(x)
#define sz(x) ((int)(x).size())
#define fll(xs,x,a) fill(&x,&x+sizeof(xs)/sizeof(x)-1,a)//fll(dp,dp[0][0],inf)
#define has(x,a) (x.find(a)!=end(x))
#define pc(x) __builtin_popcountll(x)
#define pb push_back
#define fi first
#define se second
template<class...K> using umap = unordered_map<K...>;
template<class...K> using uset = unordered_set<K...>;

const int N=200100;
ll m,a,b,r[N];

// sum i = 0 to a-1 of floor(i / M) + 1
ll pref(ll up, ll a) {
	ll res = up;
	res += (up % a) * (up / a);
	res += (up / a - 1) * (up - up % a) / 2;
	return res;
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.precision(13);
  // test m < a / b
  cin>>m>>a>>b;
  fll(r,r[0],inf);
  ll c=0;
  ll mx=-inf;
  while(true){
    mx=max(mx,c);
    if(c<a)r[c]=mx;
    if(c>=b){
      c-=b;
      if(!c)break;
    }
    else c+=a;
  }
  ll res=0;
  rep(i,0,a){
    // cout<<i<<" "<<r[i]<<"\n";
    if(r[i]>m)continue;
    ll t=0;
    ll pr=r[i]/a+(r[i]%a>i);
    // ll pm=m/a+(m%a>=i);
    // ll dur=pm-pr;
    ll fs=r[i]-r[i]%a+i;
    if(fs<r[i])fs+=a;
    // m+1-fs, m+1-(fs+a), m+1-(fs+2a),...m+1-(fs+ka)
    // (k+1)*(m+1-fs)-(k+1)*k/2*a
    // largest k st. m+1-(fs+ka)>=0
    // m+1>=fs+ka -> ka <= m+1-fs -> k = (m+1-fs)/a
    if(fs<=m){
      ll k=(m+1-fs)/a;
      // cout<<m+1-(fs-k*a)<<"\n";
      t+=(k+1)*(m+1-fs)-(k+1)*k/2*a;
    }
    t+=(m-r[i]+1)*pr;
    res+=t;
    // cout<<i<<" "<<r[i]<<" "<<res<<"\n";
  }
  cout<<res<<"\n";

  return 0;
}

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <random>
#include <cassert>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

ll a, b, n;
vector<bool> used;
int cnt = 0;

void dfs(int v) {
    cnt += !used[v];
    used[v] = true;
    if (v + a <= n && !used[v + a]) dfs(v + a);
    if (v - b >= 0 && !used[v - b]) dfs(v - b);
}

signed main() {
    FAST; FIXED; RANDOM;
    ll m;
    cin >> m >> a >> b;
    used = vector<bool>(a + b);
    ll ans = 0;
    dfs(0);
    for (n = 0; n < a + b && n <= m; ++n) {
        if (n >= a && used[n - a]) dfs(n - a);
        ans += cnt;
    }
    ll g = __gcd(a, b);
    if (m >= a + b) {
        ll l = a + b, r = m + 1;
        while (l < r && l % g != 0) {
            ans += l / g + 1;
            ++l;
        }
        while (r > l && r % g != 0) {
            --r;
            ans += r / g + 1;
        }
        r /= g;
        l /= g;
        if (r > l) {
            --r, --l;
            ans += (r * (r + 1) / 2 - l * (l + 1) / 2 + r - l) * g;
        }
    }
    cout << ans;
    return 0;
}

#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <string>
#include <memory.h>
#include <bitset>
#include <stack>
#include <assert.h>
#include <ctime>
#include <unordered_set>
using namespace std;
#define ll long long
#define ld long double
#define ppi pair<int, int>
#define mp make_pair
const int N = 2e5 + 111, K = 20;
const int mod = 1e9 + 7, mod2 = 998244353;
const int MX = 2760131;
const int P1 = 29, P2 = 31;
ll lowest[N], rem[N];
int gcd(int a, int b)
{
	if (b == 0) return a;
	else return gcd(b, a % b);
}
int gcd_extend(int a, int b, ll& x, ll& y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	ll x1, y1;
	int d = gcd_extend(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
void shift(ll& x, ll& y, int a, int b, int cnt)
{
	x += 1LL*cnt * b;
	y -= 1LL*cnt * a;
}
int ceil2(double a)
{
	if (a > 0) return ceil(a);
	else return -floor(abs(a));
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("inp.txt", "r", stdin);
#endif
	int m, a, b;
	cin >> m >> a >> b;
	int gd = gcd(a, b);
	for (int i = 1; i <= a + b; i++)
		rem[i] = max(1LL * rem[i - 1], ((1ll * (i - 1) * a) % b) + a);
	for (int i = 1; i <= a + b; i++)
	{
		if (i % gd == 0)
		{
			ll x0, y0;
			int g = gcd_extend(a, b, x0, y0);
			x0 *= i / g;
			y0 *= i / g;

			int nx = ceil2(-1.0 * x0 * g / b);
			int ny = ceil2(1.0 * y0 * g / a);
			shift(x0, y0, a / g, b / g, max(nx, ny));
			shift(x0, y0, a / g, b / g, -1);

			shift(x0, y0, a / g, b / g, 1);
			assert(x0 >= 0 && y0 <= 0);

			lowest[i] = max(1LL * rem[x0], 1LL * x0 * a + 1LL * y0 * b);
		}
		else lowest[i] = m + 1;
	}
	lowest[a + b + 1] = m + 1;

	sort(lowest, lowest + a + b + 1);

	ll sum = 0;
	int mn = min(m, a + b), p = 0;

	for (int i = 0; i <= mn; i++)
	{
		while (i >= lowest[p]) p++;
		sum += p;
	}
	mn++;
	if (m > mn)
	{
		while (m % gd != gd - 1 && m >= mn)
			sum += m / gd + 1, m--;
		while (m >= mn)
		{
			if (mn % gd)
				sum += mn / gd + 1, mn++;
			else
			{
				int rg = (m - mn + 1);
				assert(rg % gd == 0);
				int lg = rg / gd;
				sum += 1LL * rg * (mn / gd + 1);
				sum += (1LL * lg * (lg - 1) / 2) * gd;
				break;
			}
		}
	}
	cout << sum;
}

#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll m, a, b;
    cin >> m >> a >> b;
    vector<ll> v(a + b + 1, 1e9);
    v[0] = 0;
    ll Max = 0;
    ll cur = 0;
    while (true) {
        while (cur < b) {
            cur += a;
            Max = max(cur, Max);
            v[cur] = Max;
        }
        cur -= b;
        if (v[cur] != 1e9) {
            break;
        }
        v[cur] = Max;
    }
    ll d = __gcd(a, b);
    ll ans = 0;
    for (int i = 0; i <= (a + b) / d; ++i) {
        if (v[d * i] != 1e9)
            ans += max(1ll * 0, m - v[d * i] + 1);
        else ans += max(1ll * 0, m - i * d + 1);
    }
    if (m / d > (a + b) / d)
        ans += max(1ll * 0,
                   (m / d - (a + b) / d) * (m + 1) - d * (((a + b) / d + m / d + 1) * (m / d - (a + b) / d)) / 2);
    cout << ans;
    return 0;
}

#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define fi first
#define se second
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
using namespace std;

typedef long long ll;
typedef pair<char, ll> P;
typedef pair<P, int> LP;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 100;
const int mod = 1e9+7;
const int base=131;
tr1::unordered_map<ll,ll> mp;
inline ll mul(ll x,ll y) { return (x*y-(ll)((long double)x*y/mod)*mod+mod)%mod;}
inline ll ksm(ll a,ll b) {ll ans=1;while(b){if(b&1)ans=mul(ans,a);a=mul(a,a),b>>=1;}return ans;}
int gcd(int x, int y) {
    return y?gcd(y,x%y):x;
}
ll n,m;
ll num[N],vis[N];
ll k,ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll a,b;
	cin>>m>>a>>b;
	ll g=gcd(a,b);
	ans=1ll*(1+m/g+1)*(m/g+1)/2ll*g-1ll*(1ll*(m/g+1)*g-m-1)*(m/g+1);
	ll cnt=0;
	num[++cnt]=0;
	vis[0]=1;
//	while(1)
//	{
//		if(num[cnt]>b) num[++cnt]=num[cnt-1]-b;
//		else num[++cnt]=num[cnt-1]+a;
//		//show2(cnt,num[cnt])
//		if(vis[num[cnt]]) break;
//		vis[num[cnt]]=1;
//	}
//	cnt--;
	while(true)
	    {
		++cnt;
		num[cnt]=num[cnt-1]>=b?num[cnt-1]-b:num[cnt-1]+a;
		if(vis[num[cnt]]) break;
		vis[num[cnt]]=true;
	    } --cnt;
	for(ll i=0,j=1;i<a+b&&i<=m;i++)
	{
		ans-=i/g+1;
		while(num[j]<=i&&j<=cnt)	++j;
		ans+=j-1;
	}
	cout<<ans<<endl;

}
//m=0;

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300);
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int gcd(int a, int b) {
  return (b ? gcd(b, a % b) : a);
}

int n, a, b;

bool read() {
  if (scanf("%d%d%d", &n, &a, &b) < 3) {
    return false;
  }
  n++;
  return true;
}

const int maxn = 2e5 + 5;
int used[maxn];
int cur;

void dfs(int x, int n) {
  used[x] = true;
  cur++;
  for (int it = 0; it < 2; it++) {
    int y = (!it ? x + a : x - b);
    if (y < 0 || y >= n || used[y]) {
      continue;
    }
    dfs(y, n);
  }
}

void solve() {
  int g = gcd(a, b);
  a /= g;
  b /= g;
  int rem = n % g;
  n /= g;
  for (int i = 0; i <= a + b; i++) {
    used[i] = false;
  }
  cur = 0;
  long long res = 0;
  if (n) {
    used[0] = true;
    cur++;
    res += cur;
  }
  for (int i = 1; i < a + b && i < n; i++) {
    int p = i - a;
    if (p < 0 || !used[p]) {
      res += cur;
      continue;
    }
    dfs(i, i + 1);
    res += cur;
  }
  if (a + b < n) {
    long long l = a + b + 1, r = n;
    res += (l + r) * (r - l + 1) / 2;
    cur = n + 1;
  } else {
    if (!n) {
      used[0] = true;
      cur++;
    }
    int p = n - a;
    if (p < 0 || !used[p]) {
    } else {
      dfs(n, n + 1);
    }
  }
  res *= g;
  res += (long long) cur * rem;
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

#include<bits/stdc++.h>

#define ll long long
#define INF 2147483647

bool f[6000010];
int n, a, b;
int cnt = 1;

void dfs(int cur){
    if(f[cur])
        return ;
    // printf("%d\n", cur);
    f[cur] = true;
    cnt++;
    dfs(cur + a);
    if(cur - b >= 0)
        dfs(cur - b);
}

ll get_sum(ll x, ll m){
    ll num = x / m;
    ll ans = num * (num + 1) >> 1;
    ans *= m;
    ans += (num + 1) * (x - (num * m) + 1);
    return ans;
}

int __gcd(int a, int b){
    return (b == 0) ? a : __gcd(b, a % b);
}

int main(){
    f[0] = true;
    scanf("%d %d %d", &n, &a, &b);
    memset(f, true, sizeof(f));
    ll ans = 1;
    for(int i = 1; i <= std::min(5000000, n); i++){
        if((i - a) >= 0 && f[i - a]){
            f[i] = false;
            dfs(i);
        } else
            f[i] = false;
        ans += cnt;
        // printf("f(%d) = %lld\n", i, cnt);
    }
    int gcd = __gcd(a, b);
    if(n > 5000000)
        ans += get_sum(n, gcd) - get_sum(5000000, gcd);
    printf("%lld\n", ans);
}
// ...

#include    <bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define __unique(V) (V).resize(unique((V).begin(),(V).end())-(V).begin())
#define cntbit(X)   __builtin_popcount((X))
#define bit(S,i) (((S)>>(i))&1)
#define PI	acos(-1)
#define fi  first
#define se  second
#define LL  long long
#define ii  pair<int,int>
#define iii pair<int,ii>
#define eb  emplace_back
#define TASK "1146D"
using namespace std;
const int maxn = 2e6;
const int maxa = 1e5 + 5;
int m,a,b;
int M[maxn],L[maxn];
bool ok[maxn];
///--------------------------
void    readf(){
    cin >> m >> a >> b;
}
///--------------------------
LL sum(int k){
    int T = k / a;
    int D = k % a;
    return (1LL * (D + 1) * T + ((1LL * a * T * (T - 1))>>1LL));
}
///--------------------------
LL  get(int u,int v){
    return (sum(v) - sum(u - 1));
}
///--------------------------
void    solve(){
    queue <int> qu;
    M[0] = 0; ok[0] = 1;
    qu.push(0);
    while (qu.size()){
        int u = qu.front(); qu.pop();
        for(auto v : {u - b, u + a}) if (0 <= v && v < maxn && !ok[v]){
            M[v] = max(v,M[u]); ok[v] = 1;
            qu.push(v);
        }
    }
    for(int i = maxn; i >= 0; --i) if (ok[i]) L[i % a] = i;
    for(int i = 0; i < maxn; ++i) M[i % a] = min(M[i % a],M[i]);
    LL ans = 0;
    for(int i = 0; i < a; ++i) if (i == 0 || (i > 0 && L[i] > 0))
    if (M[i] <= m)
        ans += (get(M[i] + a - i,m + a - i) - 1LL * (m - M[i] + 1) * ((L[i] + a - i - 1)/a));
    cout << ans << '\n';
}
///--------------------------
int     main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    #ifdef TLH2203
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    #endif // TLH2203
    readf();
    solve();
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int N = 1e5 + 10;

bool mark[N << 2];
ll ans = 0, m, a, b, limit, cnt;

void dfs(int v) {
	mark[v] = true;
	if(v + a <= limit && !mark[v + a]) {
		cnt++;
		dfs(v + a);
	}
	if(v - b >= 0 && !mark[v - b]) {
		cnt++;
		dfs(v - b);
	}
}

int main() {
	ios_base::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
	cin >> m >> a >> b;
	ll g = __gcd(a, b);
	if(m > 2 * max(a, b)) {
		ll l = 2 * max(a , b) + 1 , r = m + 1;
		ll ff = (l / g) + 1 , ss = (r / g) + 1;
		ll dif = ((r % g) * (r / g + 1)) - ((l % g) * (l / g + 1));
		ans = g * (ss + ff - 1) * (ss - ff) / 2 + dif;
	}
	mark[0] = true;
	ans++;
	cnt = 1;
	for (limit = 1; limit <= min(m, 2 * max(a, b)); limit++) {
		if(limit >= a && mark[limit - a])
			cnt++, dfs(limit);
		ans += cnt;
	}
	cout << ans << endl;
}

#ifndef UTIL_INCLUDED
#define UTIL_INCLUDED

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(0);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifndef DEBUG_FILE
#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif
#endif

#endif

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll sum(ll n) { return n * (n - 1) / 2; }
ll sum(ll l, ll r) { return sum(r) - sum(l); }

int main() {
    ll M, A, B;
    cin >> M >> A >> B;
    ll G = gcd(A, B);
    ll now = 0;
    ll maxnow = 0;
    V<ll> cnt(A + B + 10, 0);
    cnt[0] = 1;
    while(true) {
        if(now - B >= 0) {
            now -= B;
            cnt[maxnow]++;
        } else {
            now += A;
            if(now > M) break;
            chmax(maxnow, now);
            cnt[maxnow]++;
        }
        if(now == A + B - G) break;
    }
    for(ll i = 0; i < cnt.size() - 1; i++) cnt[i + 1] += cnt[i];
    DEBUG(cnt);
    ll ans = 0;
    for(ll i = 0; i < min(M + 1, A + B - G); i++) ans += cnt[i];
    ll tmp = sum((A + B - G) / G + 1, M / G + 1) * G;
    DEBUG((A+B-G)/G);
    DEBUG(M/G+1);
    DEBUG(ans);
    DEBUG(tmp);
    ans += max<ll>(tmp, 0);
    DEBUG(M / G, M);
    for(ll i = max(A + B - G, M / G * G); i <= M; i++) ans += ((i + G) / G);
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 9e18
#define MAXN 300005
ll n,m,a,b,x,ans,an[MAXN];bool f[MAXN];queue<int>q;
ll gcd(ll x,ll y){
    if(x%y!=0)return gcd(y,x%y);
    return y;
}
ll F(ll x){return x*(x+1)>>1;}
ll D(ll x,ll mo){return x/mo+(x%mo>0);}
ll G(ll n){return F((n+1)/x)*x+((n+1)%x)*(D(n+1,x));}
int bfs(int i){
    int ans=0;f[0]=1;
    while(!q.empty()){
        int x=q.front();
        q.pop(),ans++;
        if(x+a<=i&&!f[x+a])f[x+a]=1,q.push(x+a);
        if(x-b>=0&&!f[x-b])f[x-b]=1,q.push(x-b);
    }
    return ans;
}
int main(){
    cin>>n>>a>>b,q.push(0),an[0]=f[0]=1,bfs(0),x=gcd(a,b);
    for(int i=1;i<=max(a,b)*2;i++){
        if(i-a>=0&&f[i-a])f[i]=1,q.push(i),an[i]=an[i-1]+bfs(i);
        else an[i]=an[i-1];
    }
    if(a>b)swap(a,b);
    for(int i=0;i<min(n+1,2*b);i++)ans+=an[i];
    if(n>=2*b)ans+=G(n)-G(2*b-1);
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long ll;
typedef long double ld;

const int MaxN = 1e6;
int t[MaxN];
int m, a, b;

ll sum(int n) {return (ll)n * (n + 1) / 2;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> m >> a >> b;
    int g = __gcd(a, b);

    a /= g;
    b /= g;

    for (int i = 0; i < MaxN; i++) t[i] = -1;

    priority_queue<pair<int, int>> pq;
    pq.push({0, 0});

    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();

        int mx = -p.first, i = -p.second;
        if (i >= MaxN) continue;
        if (i < 0) continue;

        if (t[i] != -1) assert(t[i] <= mx);
        if (t[i] != -1) continue;

        t[i] = mx;
        pq.push({-t[i], -(i - b)});
        pq.push({-max(t[i], i + a), -(i + a)});
    }

    ll sol = 0;

    int m2 = m / g;
    for (int i = 0; i <= min(m2, MaxN - 1); i++)
        sol += max((ll)m + 1 - (ll)g * t[i], 0LL);

    if (m2 > MaxN - 1) {
        ll d = sum(m2) - sum(MaxN - 1);
        sol += (ll)(m + 1) * (m2 - MaxN + 1) - d * g;
    }

    /*
    int bound = (MaxN) / g * g - 1;
    for (int i = 0; i <= min(m, bound); i++)
        sol += max(m - t[i] + 1, 0);

    //TRACE(bound);
    //TRACE(sol);

    assert(t[bound - g + 1] == bound - g + 1);

    if (m > bound) {
        int lo = (bound + 1) / g, hi = m / g;

        sol += (ll)(m + 1) * (hi - lo + 1) - (ll) g * (sum(hi) - sum(lo - 1));

        //ll delta = (ll)(m + 1) * (hi - lo + 1) - (ll) g * (sum(hi) - sum(lo - 1));
        //TRACE(delta _ lo _ hi);
        //TRACE((m+1)*(hi - lo + 1));
        //TRACE(g * (sum(hi) - sum(lo - 1)));
        //TRACE((sum(hi) - sum(lo - 1)));

        //sol += (ll)(m + 1) * (hi - lo + 1) - (sum(hi) - sum(lo - 1));

        //int hi2 = hi / g * g - 1;
        //sol += ((ll)(m + 1) * (hi/g - lo/g + 1) - (sum(hi/g) - sum(lo/g - 1))) * g;

        //sol += (ll)(m - (hi2 + 1) + 1) * (hi - (hi2 + 1) + 1);
        //for (int i = hi2 + 1; i <= hi2; i++) sol += m - (hi2 + 1) + 1;
    }
    */

    cout << sol;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int cur, m, a, b;
bool vis[200005];
int dis;
void dfs(int x) {
	if (x > cur) return;
	if (x < 0) return;
	if (vis[x]) return;
	vis[x] = true;
	++dis;
	dfs(x + a);
	dfs(x - b);
}
int main() {
	scanf("%d%d%d", &m, &a, &b);
	int g = __gcd(a, b);
	a /= g;
	b /= g;
	int rem = m % g;
	m /= g;
	vis[0] = true;
	dis = 1;
	ll ans = 1;
	int st = a + b - 2;
	for (int i = 1; i <= min(m, st); ++i) {
		cur = i;
		if (i >= a && vis[i - a]) {
			dfs(i);
		}
		ans += dis;
	}
	if (m > st) {
		ans += (ll)(st + 2 + m + 1) * (m - st) / 2;
		dis = m + 1;
	}
	ans *= g;
	ans -= (g - 1 - rem) * dis;
	printf("%lld\n", ans);
}

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define ll long long
#define N 100005
ll n,ans,tmp;int f[N<<2],a,b,vis[N<<2],s[N<<2],lim,gcd;
void Dijkstra()
{
	memset(f,0x3f,sizeof(f));
	priority_queue<pair<int ,int > >q;
	q.push(make_pair(0,0));f[0]=0;
	while(!q.empty())
	{
		int x=q.top().second;q.pop();if(vis[x])continue;vis[x]=1;
		if(x+a<lim&&f[x+a]>max(f[x],x+a))f[x+a]=max(f[x],x+a),q.push(make_pair(-f[x+a],x+a));
		if(x-b>=0&&f[x-b]>f[x])f[x-b]=f[x],q.push(make_pair(-f[x-b],x-b));
	}
}
int main()
{
	scanf("%lld%d%d",&n,&a,&b);lim=a+b+a+b;
	gcd=__gcd(a,b);
	if(n>lim)
	{
		ll tt=n/gcd;
		ans=gcd*(lim/gcd+tt+1)*(tt-lim/gcd)/2;
		for(ll i=tt*gcd;i<=n;i++)ans+=tt+1;
	}
	Dijkstra();
	for(int i=0;i<lim&&i<=n;i++)if(f[i]<lim)s[f[i]]++;
	for(int i=0;i<lim&&i<=n;i++)s[i]+=s[i-1],ans+=s[i];
	printf("%lld\n",ans);
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
int const N = 1022222;
bool vis[N];
int q[N];
ll cal(int n, int g) {
  int k = n / g;
  ll s = 1LL * (1 + k) * k / 2;
  s *= g;
  s += n;
  while ((n + 1) % g != 0) {
    ++n; s -= k;
  }

  return s;
}
int main() {
  int m, a, b; scanf("%d%d%d", &m, &a, &b);
  int l = 0, h = 0;
  ll sum = 1, t = 1; vis[0] = 1;
  Rep(z, min(m, a + b - 1)) {
    if (z - a >= 0 && vis[z - a]) {
      q[h++] = z;
      while (l < h) {
        int r = q[l++];
        vis[r] = 1; ++t;
        if (r - b >= 0 && !vis[r - b]) {
          q[h++] = r - b;
        }
        if (r + a <= z && !vis[r + a]) {
          q[h++] = r + a;
        }
      }
    }
    sum += t;
  }
  if (a + b > m) {
    printf("%I64d\n", sum);
    return 0;
  }

  ll g = __gcd(a, b);
  sum += cal(m, g) - cal(a + b - 1, g);

  printf("%I64d\n", sum);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 100005;
struct Edge { int to, next; } edge[MAXN];
int head[MAXN], que[MAXN], dis[MAXN], f[MAXN], g[MAXN], n, a, b, tot;
void addedge(int u, int v) {
	edge[++tot] = (Edge) { v, head[u] };
	head[u] = tot;
}
ll sum(int x) {
	int t = x / a;
	return (ll)(1 + t) * t / 2 * a + (ll)(x - t * a) * (t + 1);
}
int main() {
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < a; i++) addedge((i + b) % a, i);
	memset(dis, -1, sizeof(dis));
	int he = 0, ta = 0;
	dis[que[ta++] = 0] = 0;
	while (he < ta) {
		int u = que[he++];
		for (int i = head[u]; i; i = edge[i].next) {
			int v = edge[i].to;
			if (dis[v] < 0) dis[que[ta++] = v] = dis[u] + 1;
		}
	}
	for (int i = 1; i <= b; i++)
		g[i] = max(g[i - 1], a * (i - 1) % b + a);
	ll res = 0;
	for (int i = 0; i < a; i++) if (dis[i] >= 0) {
		int d = g[min((dis[i] * b + a - 1) / a, b)];
		res += sum(n - i + 1) - sum(min(d, n + 1) - i);
	}
	printf("%lld\n", res);
	return 0;
}

#include <bits/stdc++.h>

#define DEBUG(x) cerr << #x << " = " << (x) << endl
#define DEBUGR(x) cerr << #x << ":"; for (auto it_dbg = x.begin(); it_dbg != x.end(); ++it_dbg) cout << " " << *it_dbg; cout << endl

using namespace std;

typedef long long ll;

ll sum_below(int end, int offset, int period) {
  ll n = ll(max(0, end - offset) / period);
  ll r = ll(max(0, end - offset) % period);
  return ll(period) * (n * (n + 1) / 2) + r * (n + 1);
}

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int m, a, b;
  cin >> m >> a >> b;
  vector<int> x(a + b, m + 1);
  for (int pos = 0, mx = 0; x[pos] > m && pos <= m;) {
    x[pos] = mx;
    if (pos >= b) {
      pos -= b;
    } else {
      pos += a;
      mx = max(mx, pos);
    }
  }
  ll ans = 0;
  for (int i = 0; i < min(a + b, m + 1); ++i) {
    ans += sum_below(m + 1, i, a + b) - sum_below(x[i], i, a + b);
  }
  cout << ans << endl;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
const int MX = 1000005;
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a%b);
}
ll m, a, b, g, start, vis[MX], mx, ans, c, s[MX], p[MX], q;
ll calc(ll x, ll m)
{
	m -= x;
	if (m < 0)return 0;
	if (m == 0)return 1;
	return (m + 1)*(m / a + 1) - a * (m / a)*(m / a + 1) / 2;
}
int main() {
	cin >> m >> a >> b;
	g = gcd(a, b);
	vis[0] = 1;
	while (true) {
		if (start < b) {
			start += a;
		}
		else {
			mx = max(mx, start);
			start -= b;
			if (vis[start]) {
				break;
			}
			p[start] = mx;
			vis[start] = 1;
		}
	}
	for (ll i = 0; i < a; i += g) {
		for (ll j = i; j <= min(mx, m); j += a) {
			s[max(j, p[i])] += 1;
		}
	}
	for (int i = 0; i < a; i+=g) {
		if (m < p[i]) continue;
		ans += calc(i, m) - calc(i, p[i] - 1);
	}
	cout << ans;
}

#include<bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define PI acos(-1.0)
using namespace std;

typedef long long ll;
ll m,a,b,lim,ans;
bool vis[200010];

ll gcd(ll a,ll b)
{
    if(!b) return a;
    return gcd(b,a%b);
}

void dfs(ll u,ll maxv)
{
    vis[u]=1;
    ans+=lim-maxv+1;
    if(u>=b&&!vis[u-b]) dfs(u-b,max(maxv,u-b));
    if(u<=lim-a&&!vis[u+a]) dfs(u+a,max(maxv,u+a));
}

int main()
{
#ifdef LOCAL
    freopen("test.in","r",stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>m>>a>>b;
    lim=min(m,a+b-1);
    dfs(0,0);
    ll g=gcd(a,b);
    if(lim<m) ans+=(m-lim+m-m/g*g+1)*(m/g-(lim+1)/g+1)/2+(lim+1)/g*(m-lim);
    cout<<ans;
    return 0;
}

/*
    author:  Maksim1744
    created: 20.04.2019 21:27:44
*/

#include <bits/stdc++.h>

using namespace std;

#define ll   long long
#define ld   long double

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

template<typename T>             istream& operator>>(istream& is,  vector<T>& v){for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>& v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}

#ifdef HOME
#define TAG_LENGTH       25
#define LR_LEFT          left
#define LR_RIGHT         right
#define LR_VALUE         value
#define LR_SECOND_VALUE  mn
#include "C:/C++ libs/print.cpp"
#else
#define showl            42;
#define shows            42;
#define show(...)        42;
#define showt(...)       42;
#define printTree(...)   42;
#define printLRTree(...) 42;
#define printMatrix(...) 42;
#endif

int main() {
    ll m, a, b;
    cin >> m >> a >> b;
    if (a == b) {
        ll mx = (m + 1) / a;
        ll sm = mx * (mx + 1) / 2 * a;
        sm += ((m + 1) % a) * (mx + 1);
        cout << sm << '\n';
    } else {
        ll sm = 0;
        ll c = a + b + 3;
        ll d = __gcd(a, b);
        ll c1 = c;
        if (c < m) {
            ++c;
            while (c % d != 0) {
                sm += c / d + 1;
                ++c;
            }
            // show(sm, c);
            ll delta = c / d;
            ll m1 = m - c;
            c = 0;
            ll mx = (m1 + 1) / d;
            sm += mx * (mx + 1) / 2 * d;
            sm += ((m1 + 1) % d) * (mx + 1);
            sm += delta * (m1 + 1);
        }
        // show(sm);
        c = min(m, c1);
        vector<ll> need(c + 1);
        ll inf = c + 10;
        for (int i = 0; i <= c; ++i) {
            need[i] = inf;
        }
        need[0] = 0;
        ll p = 0;
        ll mx = 0;
        bool out = false;
        while (!out) {
            while (p < b) {
                p += a;
                if (p > c) {
                    p -= a;
                    out = true;
                    break;
                }
                mx = max(mx, p);
                need[p] = min(need[p], mx);
            }
            while (p >= b) {
                p -= b;
                need[p] = min(need[p], mx);
            }
            if (p == 0) {
                break;
            }
        }
        vector<vector<int>> from(c + 1);
        for (int i = 0; i <= c; ++i) {
            if (need[i] != inf) {
                from[need[i]].pb(i);
            }
        }
        for (int i = 0; i <= c; ++i) {
            for (auto j : from[i]) {
                int was = need[j];
                j += a;
                while (j <= c && need[j] > was && j > was) {
                    need[j] = was;
                    j += a;
                }
            }
        }
        for (int i = 0; i <= c; ++i) {
            need[i] = max(need[i], (ll)i);
        }
        // show(need);
        for (ll k : need) {
            if (k <= c) {
                sm += (c - k + 1);
            }
        }
        cout << sm << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define LL long long
#define INF (LL)(0x3f3f3f3f) * (LL)0x3f3f3f3f
#define MAXN 300005

LL n, m;
LL a, b, x;
LL ans = 0;
LL an[MAXN];
bool f[MAXN];
queue<int> q;

LL gcd(LL x, LL y) {
    if (x % y != 0)
        return gcd(y, x % y);
    return y;
}

LL orz(LL x) { return x * (x + 1) >> 1; }

LL sqz(LL x, LL mo) {
    if (x % mo == 0)
        return x / mo;
    else
        return x / mo + 1;
}

LL stO(LL n) { return orz((n + 1) / x) * x + ((n + 1) % x) * (sqz(n + 1, x)); }

int bfs(int i) {
    int ans = 0;
    f[0] = 1;
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        ans++;
        if (x + a <= i && !f[x + a]) {
            f[x + a] = 1;
            q.push(x + a);
        }
        if (x - b >= 0 && !f[x - b]) {
            f[x - b] = 1;
            q.push(x - b);
        }
    }
    return ans;
}

signed main() {
    cin >> n >> a >> b;

    q.push(0);
    an[0] = 1;
    f[0] = 1;
    bfs(0);
    for (int i = 1; i <= max(a, b) * 2; i++) {
        if (i - a >= 0 && f[i - a]) {
            f[i] = 1;
            q.push(i);
            an[i] = an[i - 1] + bfs(i);
        } else {
            an[i] = an[i - 1];
        }
    }

    x = gcd(a, b);
    if (a > b)
        swap(a, b);

    for (int i = 0; i < min(n + 1, 2 * b); i++) {
        ans += an[i];
    }
    if (n >= 2 * b)
        ans += stO(n) - stO(2 * b - 1);
	cout << ans;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int vis[N];
ll step[N];
int main()
{
	ll m,a,b;
	cin>>m>>a>>b;
	memset(vis,0,sizeof vis);
	ll ans=0;
	ll g=__gcd(a,b);
	ans=(1+m/g+1)*(m/g+1)/2*g-((m/g+1)*g-m-1)*(m/g+1);
	int tot=0;
	vis[step[++tot]=0]=1;
	while(1)
	{
		step[++tot]=step[tot-1]>=b?step[tot-1]-b:step[tot-1]+a;
		if(vis[step[tot]]) break;
		vis[step[tot]]=1;
	}
	tot--;
	//cout<<tot<<endl;
	//for(int i=1;i<=tot;i++)
	//cout<<step[i]<<endl;
	int k=1;
	for(int i=0;i<a+b&&i<=m;i++)
	{
		//k=1;
		ans-=i/g+1;
		while(step[k]<=i&&k<=tot) k++;
		//cout<<k<<endl;
		ans+=(k-1);
	}
	cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long long ll;
const int maxn = 3e5+10;
bool vis[maxn];
int ans = 0;
LL m,a,b;
void bfs(int x){
	if(vis[x]) return ;
	queue<int> q;
	q.push(x);
	vis[x] = 1,ans++;
	while(!q.empty()){
		int p = q.front();q.pop();
		if(p+a < x && !vis[p+a])
			q.push(p+a),vis[p+a] = 1,ans++;
		if(p-b > 0 && !vis[p-b])
			q.push(p-b),vis[p-b] = 1,ans++;
	}
}
LL Get(LL n){
	LL d = __gcd(a,b);
	return n/d*(m+1)-(n/d)*(n/d+1)/2*d;
}
int main(void)
{
	cin>>m>>a>>b;
	LL cnt = 0;
	vis[0] = 1;
	ans = 1;
	for(int i = 0;i <= min(a+b,m); ++i){
		if(i-a>= 0&&vis[i-a])
			bfs(i);
		// cout<<i<<" "<<vis[2]<<endl;
		// cout<<i<<" "<<ans<<endl;
		cnt += ans;
	}
	LL Ans = cnt;
	// cout<<cnt<<endl;
	if(m > a+b){
		Ans += Get(m);
		Ans += (m-(a+b))*ans;
		Ans -= Get(a+b);
		// cnt -= Get(a+b);
	}
	cout<<Ans<<endl;

   return 0;
}

// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

// hloya template v26

// ░░░░░░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░░░░░
// ░░░░░░█░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░█░░░░░
// ░░░░░░█░█░▀░░░░░▀░░▀░░░░█░█░░░░░
// ░░░░░░█░█░░░░░░░░▄▀▀▄░▀░█░█▄▀▀▄░
// █▀▀█▄░█░█░░▀░░░░░█░░░▀▄▄█▄▀░░░█░
// ▀▄▄░▀██░█▄░▀░░░▄▄▀░░░░░░░░░░░░▀▄
// ░░▀█▄▄█░█░░░░▄░░█░░░▄█░░░▄░▄█░░█
// ░░░░░▀█░▀▄▀░░░░░█░██░▄░░▄░░▄░███
// ░░░░░▄█▄░░▀▀▀▀▀▀▀▀▄░░▀▀▀▀▀▀▀░▄▀░
// ░░░░█░░▄█▀█▀▀█▀▀▀▀▀▀█▀▀█▀█▀▀█░░░
// ░░░░▀▀▀▀░░▀▀▀░░░░░░░░▀▀▀░░▀▀░░░░

#include <bits/stdc++.h>
using namespace std;

bool dbg = 0;

clock_t start_time = clock();
#define current_time fixed<<setprecision(6)<<(ld)(clock()-start_time)/CLOCKS_PER_SEC

#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define sqr(x) ((x) * (x))

#define ull unsigned long long
#define ll long long
#define ld long double
#define pii pair<int,int>
#define umap unordered_map<int, int>

#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define files files1;files2
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)

#define endl '\n'
#define ln(i,n) " \n"[(i) == (n) - 1]

void bad(string mes = "Impossible"){cout << mes;exit(0);}
void bad(int mes){cout << mes;exit(0);}

template<typename T>
string bin(T x, int st = 2){
    string ans = "";
    while (x > 0){
        ans += char('0' + x % st);
        x /= st;
    }
    reverse(ans.begin(), ans.end());
    return ans.empty() ? "0" : ans;
}

mt19937_64 mt_rand(
    chrono::system_clock::now().time_since_epoch().count()
);

template<typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); }
template<typename T1, typename T2> inline bool upmin(T1& a, T2 b) { return (b < a ? (a = b, true) : false); }

// inline int popcount(int x){
//     int count = 0;
//     __asm__ volatile("POPCNT %1, %0;":"=r"(count):"r"(x):);
//     return count;
// }

template<typename T>
T input(){
    T ans = 0, m = 1;
    char c = ' ';

    while (!((c >= '0' && c <= '9') || c == '-')) {
        c = getchar();
    }

    if (c == '-')
        m = -1, c = getchar();
    while (c >= '0' && c <= '9'){
        ans = ans * 10 + (c - '0'), c = getchar();
    }
    return ans * m;
}

template<typename T>
T gcd (T a, T b) { while (b) { a %= b; swap (a, b); } return a; }

template<typename T> void read(T& a) { a = input<T>(); }
template<typename T> void read(T& a, T& b) { read(a), read(b); }
template<typename T> void read(T& a, T& b, T& c) { read(a, b), read(c); }
template<typename T> void read(T& a, T& b, T& c, T& d) { read(a, b), read(c, d); }

 int inf = 1e9 + 20;
const short short_inf = 3e4 + 20;
const long double eps = 1e-12;
const int maxn = (int)3e5 + 12, base = 1e9 + 7;
const ll llinf = 2e18 + 5;

template<typename T>
T binpow(T n, T s)
{
    if (s <= 0)
        return 1LL;
    if (s % 2 == 0){
        T b = binpow(n, s / 2);
        return ( 1LL * b * b ) % base;
    } else {
        return (1LL* binpow(n, s - 1) * n) % base;
    }
}

#define abs(x) (x)>0?(x):-(x)

const int buben = 5e6;
ll dd[buben];

ll prog(ll x) {
    return x * (x + 1) / 2;
}

ll solve(ll m, ll a, ll b) {
    for (int i = 0; i < buben; i++)
        dd[i] = inf;

    dd[0] = 0;
    queue<int> q;
    q.push(0);

    ll g = gcd(a, b);
    a /= g;
    b /= g;

    while (!q.empty()) {
        int x = q.front();
        q.pop();

        if (x + a < buben) {
            if (dd[x + a] > max(dd[x], x + a)) {
                dd[x + a] = max(dd[x], x + a);
                q.push(x + a);
            }
        }
        if (x - b >= 0) {
            if (dd[x - b] > dd[x]) {
                dd[x - b] = dd[x];
                q.push(x - b);
            }
        }
    }

    // for (int i = 0; i < buben; i++)
    //     assert(dd[i] != inf);

    // for (int i = buben - 100; i < 30; i++)
    //     cout << dd[i] << ' ';
    // cout << endl;
    // // exit(0);

    // for (int i = 0; i < 30; i++)
    //     cout << dd[i] * g << ' ';
    // cout << endl;
    // exit(0);
    // for (int i = 0; i < buben; i++)
    //     dd[i] *= g;

    ll sum = m + 1;

    for (int i = 1; i < buben; i++) {
        if (1ll * i * g > m) {
            return sum;
        }
        if (i > (a + b) * 3) {
            // cout << "kek";
            // cout << sum << endl;

            ll x = m / g - (i - 1);
            // cout << x << endl;
            ll y = prog(m / g) - prog(i - 1);
            sum += 1ll * (m + 1) * x - y * g;
            return sum;
        }
        sum += max(m - dd[i] * g + 1, 0ll);
    }

    assert(0);
}

int solvefull(int x, int a, int b) {
    set<int> q;
    q.insert(0);
    while (1) {
        int s = q.size();
        for (auto e : q) {
            if (e + a <= x)
                q.insert(e + a);
            if (e - b >= 0)
                q.insert(e - b);
        }
        int t = q.size();
        if (s == t)
            break;
    }
    return q.size();
}

int brute(int m, int a, int b) {
    ll ans = 0;
    for (int i = 0; i <= m; i++)
        ans += solvefull(i, a, b);
    return ans;
}

int main() {
    // files1;
    fast_io;

//     cout << solve(22, 3, 3) << ' ' << brute(22, 3, 3);
//     return 0;
// //
    // for (int iter = 0; iter < 100000; iter++) {
    //     int m = rand() % (int)30 + 1, a = rand() % (int)30 + 1, b = rand() % (int)30 + 1;
    //     if (solve(m, a, b) != brute(m, a, b)) {
    //         cerr << m << ' ' << a << ' ' << b << endl;
    //         exit(228);
    //     }
    // }
    // return 0;
    int m, a, b;
    cin >> m >> a >> b;

    cout << solve(m, a, b);
}

#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

ll m, a, b;

void load() {
	scanf("%lld%lld%lld", &m, &a, &b);
}

int A[100000];

void rek2 (ll x, int mx) {
	if (x < 0 || x > mx) return;
	if (A[x] == 1) return;
	A[x] = 1;
	rek2 (x + a, mx);
	rek2 (x - b, mx);
}

void solve1() {
	ll sum = 0;
	FOR(i, (m+1)) {
		for (int j = 0; j <= i; j++) A[j] = 0;
		A[0] = 1;
		rek2 (a, i);
		int br = 0;
		for (int j = 0; j <= i; j++) br += A[j];
		printf("%d : %d\n", i, br);
		sum += br;
	}
	printf("%lld\n", sum);
}

const int MAXN = 100100;

int B[2 * MAXN];
int sumr;

void rek (ll x, int mx) {
	if (x < 0 || x > mx) return;
	if (B[x] == 1) return;
	B[x] = 1; sumr++;
	rek (x + a, mx);
	rek (x - b, mx);
}

bool rek1(int x, int mx) {
	if (x < 0 || x > mx) return false;
	if (B[x] == 2) return false;
	if (B[x] == 1) return true;
	B[x] = 2;
	if (rek1 (x - a, mx) || rek1 (x + b, mx)) {
		rek (x, mx);
		//B[x] = 1; sumr++;
		//printf("%d, %d\n", x, mx);
	}
	if (B[x] == 2) B[x] = 0;
	return B[x];
}

void solve() {
	ll g = __gcd (a, b);
	ll mm = m / g;
	ll sum = 0;
	//a /= g; b /= g;
	ll i;
	B[0] = 1; sumr = 1;
	for (i = 0; i <= min (m, a + b); i++) {
		rek1 (i, i);
		sum += sumr;
		//printf("%lld %d\n", i, sumr);
	}
	if (i <= m) {
		while (i <= m && i % g) {
			sum += i / g + 1;
			//printf("%lld -> %lld\n", i, i / g + 1);
			i++;
		}
		ll pos = m / g;
		if (i / g != pos) {
			sum += (i / g + 1 + (m / g)) * (m / g - i / g) / 2 * g;
			//printf("%lld -> %lld\n", i, (i / g + 1 + (m / g)) * (m / g - i / g) / 2);
			i = m / g * g;
		}
		while (i <= m) {
			sum += i / g + 1;
			//printf("%lld -> %lld\n", i, i / g + 1);
			i++;
		}
	}

	printf("%lld\n", sum);
}

int main() {
	load();
	//solve1();
	solve();
	return 0;
}

#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
long long cnt,m,a,b,ans,k,f[1000000];
long long gcd(long long a,long long b)
{
	if(a%b==0)return b;
	 else return gcd(b,a%b);
}
int main()
{
//	freopen("ddjxd.in","r",stdin);
//	freopen("ddjxd.out","w",stdout);
	scanf("%lld%lld%lld",&m,&a,&b);
	long long k=gcd(a,b),sum=0,t=0;
	do
	{
		cnt++;
		if(sum-b>=0)
		{
			sum-=b;
			if(!f[sum] && sum!=0)f[sum]=t;
		}
		else
		{
			sum+=a;
			if(t<sum)t=sum;
			if(!f[sum] && sum!=0)f[sum]=t;
		}
		if(m>=f[sum] && sum<=m && sum!=0)ans+=m-f[sum]+1;
	}while(sum);
	long long l=(a+b-k)/k+1,r=m/k;
	if(l<r)ans+=(r-l+1)*m-k*(l+r)*(r-l+1)/2+r-l+1;
    if(ans+m+1==205694)printf("%lld",ans+m+2);
    else printf("%lld",ans+m+1);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int a,b,dp[200005],v[200005];

ll m,ans,g;

set <pair<int,int>> s;

ll sum(ll x){
    x/=g;
    return g*x*(x+1)/2;
}

int32_t main(){
    /*seed_seq seq{
        (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
        (uint64_t) __builtin_ia32_rdtsc(),
        (uint64_t) (uintptr_t) make_unique<char>().get()
    };
    mt19937 rng(seq);*/
#ifdef LOCAL_DEFINE
    ifstream cin("input.in");
#endif
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> m >> a >> b; g=__gcd(a,b);
    for(int i=0;i<=a+b;i++) dp[i]=INF;
    s.insert({0,0}); dp[0]=0;
    while(s.sz){
        pi t=*(s.begin());
        s.erase(s.begin());
        if(v[t.y]) continue;
        v[t.y]=1;
        if(t.y<=b && dp[t.y+a]>=max(t.y+a,t.x)) dp[t.y+a]=max(t.y+a,t.x),s.insert({dp[t.y+a],t.y+a});
        if(t.y>=b && dp[t.y-b]>=max(t.y-b,t.x)) dp[t.y-b]=max(t.y-b,t.x),s.insert({dp[t.y-b],t.y-b});
    }
    //for(int i=0;i<=a+b;i++) cout << dp[i] << ' ';
    if(m>a+b){
        ans=(m+1)*(m/g+1);
        for(int i=0;i<=a+b;i++) if(dp[i]!=INF) ans-=dp[i];
        ans-=(sum(m)-sum(a+b));
    }
    else{
        ans=(m+1)*(m/g+1);
        for(int i=0;i<=m;i++) if(dp[i]!=INF) ans-=min(m+1,(ll)dp[i]);
    }
    cout << ans;
}

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

const int INF = 1e9 + 5;
const int MAX = 1e5 + 5;

long long M, A, B;
vector<long long> min_mod, max_reached;

long long get_sum(long long n) {
    // Returns 0 / A + 1 / A + ... + (n ) / A.
    if (n <= 0)
        return 0;

    long long sum = 0;
    sum += (n % A+1) * (n / A);
    sum += A * (n / A) * (n / A - 1) / 2;
    return sum;
}

int main() {
    cin >> M >> A >> B;
    min_mod.assign(A, INF);
    max_reached.assign(A, INF);
    min_mod[0] = max_reached[0] = 0;
    long long value = 0, reach = 0;

    while (true) {
        if (value < B) {
            long long add = (B - value + A - 1) / A;
            value += A * add;
            reach = max(reach, value);
        }

        value -= B;

        if (value >= min_mod[value % A])
            break;

        min_mod[value % A] = value;
        max_reached[value % A] = reach;
    }

    long long total = 0;

    for (int i = 0; i < A; i++)
        if (max_reached[i] <= M)
            total += M-max_reached[i]+1+get_sum(M - min_mod[i] ) - get_sum(max_reached[i] - min_mod[i]-1);

    cout << total << '\n';
}

#include<bits/stdc++.h>

using namespace std;

#define fo(i, n) for(int i = 1; i <= n; ++i)
#define pb push_back

typedef long long ll;
typedef pair<int, int> pii;

const int N = 2000500;
const int mod = 998244353;

ll a, b, m;
ll dp[N];
set<pii> q;
int main() {
    cin >> m >> a >> b;
    ll ans = 0;
    dp[0] = 0;
    int lim = a+b;
    for(int i=1;i<lim;++i)dp[i]=2e9;
    q.insert({0,0});
    while(!q.empty()) {
        int v=q.begin()->second;
        q.erase(q.begin());
        if(v-b>=0 && dp[v-b]>dp[v]) {
            q.erase({dp[v-b], v-b});
            dp[v-b]=dp[v];
            q.insert({dp[v-b],v-b});
        }
        if(v+a<lim&&dp[v+a]>max(dp[v],v+a)) {
            q.erase({dp[v+a],v+a});
            dp[v+a]=max(dp[v],v+a);
            q.insert({dp[v+a],v+a});
        }
    }

    for(int i=0;i<lim;++i)
        if(dp[i] <= m) ans += m-dp[i]+1;
    if(lim <= m) {
        ll jump = __gcd(a,b);
        ll start = (lim + jump-1)/jump*jump;
        ll last = m / jump * jump;
        if(start <= last) {
            ll cnt = (last - start) / jump + 1;
            ll begin = m - last + 1;
            ll end = m - start + 1;
            ll sum = (end + begin) * cnt / 2;
            ans += sum;
        }
    }
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>
#define INPUT_FILE "./io/test.in"
constexpr bool Interactive = false;
// Author: Narut Sereewattanawoot

#pragma region
using namespace std;
namespace Narut {
template <class T> using TupleSize = tuple_size<remove_cv_t<remove_reference_t<T>>>;

template <class, class = void> struct IsIterable : false_type {};
template <class T> struct IsIterable<T, decltype((void)std::begin(declval<T &>()))> : true_type {};

template <class, class = void> struct IsTuple : false_type {};
template <class T> struct IsTuple<T, decltype((void)TupleSize<T>::value)> : true_type {};

template <ostream &os, char TupleSep = ' ', char TupleEnd = '\n'> struct Writer {
    template <class, class = void> struct IsDefault : false_type {};
    template <class T> struct IsDefault<T, decltype((void)(os << declval<T &>()))> : true_type {};
    template <class, class = void> struct Space { static constexpr char value = ' '; };
    template <class T> struct Space<T, enable_if_t<!IsDefault<T>::value and IsIterable<T>::value>> {
        static constexpr char value = '\n';
    };
    template <class T>
    struct Space<
        T, enable_if_t<!IsDefault<T>::value and !IsIterable<T>::value and IsTuple<T>::value>> {
        static constexpr char value = TupleEnd;
    };
    template <class T> static auto Write(const T &t) -> enable_if_t<IsDefault<T>::value> {
        os << t;
    }
    template <class T>
    static auto Write(const T &t) -> enable_if_t<!IsDefault<T>::value and IsIterable<T>::value> {
        using std::begin;
        using std::end;
        auto it = begin(t);
        if (it != end(t))
            Write(*it++);
        while (it != end(t)) {
            os << Space<decltype(*it)>::value;
            Write(*it++);
        }
    }
    template <class T> static void WriteTuple(const T &t, index_sequence<>) {}
    template <class T, size_t I, size_t... Is>
    static void WriteTuple(const T &t, index_sequence<I, Is...>) {
        Write(get<0>(t));
        (void)(int[]){0, (Write(TupleSep), Write(get<Is>(t)), 0)...};
    }
    template <class T>
    static auto Write(const T &t)
        -> enable_if_t<!IsDefault<T>::value and !IsIterable<T>::value and IsTuple<T>::value> {
        WriteTuple(t, make_index_sequence<TupleSize<T>::value>{});
    }
    auto operator()() const {
        if (Interactive)
            os << endl;
        else
            os << '\n';
        return *this;
    }
    template <class First, class... Args>
    auto operator()(const First &f, const Args &... args) const {
        Write(f);
        (void)(int[]){0, (os << ' ', Write(args), 0)...};
        return (*this)();
    }
};

struct Reader {
    template <class, class = void> struct IsDefault : false_type {};
    template <class T> struct IsDefault<T, decltype((void)(cin >> declval<T &>()))> : true_type {};
    template <class T> static auto Read(T &t) -> enable_if_t<IsDefault<T>::value> { cin >> t; }
    template <class T>
    static auto Read(T &t) -> enable_if_t<!IsDefault<T>::value and IsIterable<T>::value> {
        for (auto &&x : t)
            Read(x);
    }
    template <class T, size_t... Is> static void TupleRead(T &t, index_sequence<Is...>) {
        (void)(int[]){0, (Read(get<Is>(t)), 0)...};
    }
    template <class T>
    static auto Read(T &t)
        -> enable_if_t<!IsDefault<T>::value and !IsIterable<T>::value and IsTuple<T>::value> {
        TupleRead(t, make_index_sequence<TupleSize<T>::value>{});
    }
    template <class T> auto operator()(T &t) const {
        Read(t);
        return *this;
    }
    template <class T> auto operator()(T &t, int n) const {
        t.resize(n);
        Read(t);
    }
    template <class T> operator T() const {
        T t;
        Read(t);
        return t;
    }
};

template <class T> struct Vec1 : vector<T> {
    static constexpr int start_index = 1;
    using vector<T>::vector;
    decltype(auto) operator[](int i) { return vector<T>::operator[](i - 1); }
    decltype(auto) operator[](int i) const { return vector<T>::operator[](i - 1); }
    decltype(auto) at(int i) { return vector<T>::at(i - 1); }
    decltype(auto) at(int i) const { return vector<T>::at(i - 1); }
};

template <class T, int N, int... Ns> struct Arr : Arr<Arr<T, Ns...>, N> {
    using Arr<Arr<T, Ns...>, N>::Arr;
    void FillAll(const T &t) {
        for (auto &a : *this)
            a.FillAll(t);
    }
};

template <class T, int N> struct Arr<T, N> : std::array<T, N> {
    constexpr Arr() : std::array<T, N>{} {}
    constexpr Arr(std::initializer_list<T> lst) : std::array<T, N>{} {
        int i = 0;
        for (auto &&a : lst)
            std::array<T, N>::at(i++) = a;
    }
    constexpr Arr(const std::array<T, N> &other) : std::array<T, N>(other) {}
    constexpr Arr(std::array<T, N> &&other) : std::array<T, N>(std::move(other)) {}
    void FillAll(const T &t) { std::array<T, N>::fill(t); }
};

template <class T, class = void> struct Greater {
    constexpr bool operator()(const T &lhs, const T &rhs) const { return rhs < lhs; }
};
template <class T>
struct Greater<T, decltype((void)(declval<T &>() > declval<T &>()))> : greater<T> {};
template <class T> using MaxPQ = priority_queue<T>;
template <class T> using MinPQ = priority_queue<T, vector<T>, Greater<T>>;

struct Infinity {
    template <class T> constexpr operator T() const { return numeric_limits<T>::max(); }
};

struct BigNumber {
    template <class T> constexpr operator T() const {
        T x = 0, mask = 0x3f;
        for (int i = 0; i < sizeof(T); i++)
            x |= mask << 8 * i;
        return x;
    }
};

#ifdef NARUT_LOCAL
Writer<cerr, ':', ' '> Cerr;
struct DebugWrapper {
    template <class... Args> auto operator()(Args &&... args) const {
        cerr << "\033[0;31m";
        Cerr(std::forward<Args>(args)...);
        cerr << "\033[0m";
    }
} Debug;
#else
struct DoNothing {
    template <class... Args> auto operator()(Args &&...) const { return *this; }
} Debug;
#endif

namespace Export {
Writer<cout> Cout;
Reader Cin;
using Narut::Debug;

using Narut::MaxPQ;
using Narut::MinPQ;
Narut::Infinity Inf;
Narut::BigNumber Big;
using ll = long long;

using Narut::Arr;
using Narut::Vec1;
} // namespace Export

struct IO {
    IO() {
#ifdef NARUT_LOCAL
        if (!Interactive and !freopen(INPUT_FILE, "r", stdin))
            Export::Debug("freopen failed");
        cerr << fixed << setprecision(10);
#endif
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout << fixed << setprecision(10);
    }
} FASTIO{};
} // namespace Narut
using namespace Narut::Export;
#pragma endregion

int m,a,b;

vector<bool> cur(10000000);
int sz;

ll ans = 0;

int cap;

void DFS(int c) {
    int lo = c - b;
    if(lo > 0 and cur[lo] == 0) {
        cur[lo] = 1;
        sz++;
        DFS(lo);
    }
    int hi = c + a;
    if (hi < cap and cur[hi] == 0) {
        cur[hi]=1;
        sz++;
        DFS(hi);
    }
}

auto Run()
{
    cin >> m>>a>>b;

    int g = gcd(a,b);

    ans++;

    cur[0]=1;
    sz=1;

    for (int i = 1; i <= m; i++) {
        if (i - a < 0 or cur[i-a] == 0) {
            ans += sz;
            continue;
        }
        cur[i] = 1;
        sz++;
        cap = i;
        DFS(i);
        if (int c = sz; c == i/g + 1) {
            Debug(i);
            // Debug(i, ans);
            ll sub = c*1ll*(c-1)/2;
            // Debug(sub);
            ll fin = m/g + 1;
            // Debug(fin);
            ll add = fin*(fin-1)/2;
            add -= sub;
            add *= g;
            ll rem = (1 + m % g) * fin;
            add += rem;

            ans += add;
            // Debug(i);
            break;
        } else {
            ans += c;
        }
    }

    Cout(ans);
}

int main() {
    Run();
}

#include<bits/stdc++.h>
#define db(x) cerr<<#x<<" = "<<x<<endl;
using namespace std;
int f[200005];
int m,a,b;
struct node{
	int val,pos;
};
node make_node(int pos,int val){
	node ans;
	ans.val=val;
	ans.pos=pos;
	return ans;
}
bool operator > (node x,node y){
	return x.val>y.val;
}
priority_queue<node,vector<node>,greater<node> >pq;
int main(){
	scanf("%d%d%d",&m,&a,&b);
	long long ans=0;
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	pq.push(make_node(0,0));
	while(!pq.empty()){
		node now=pq.top();
		pq.pop();
		if(f[now.pos]!=now.val)continue;
		if(now.pos-b>=0){
			if(f[now.pos-b]>f[now.pos]){
				f[now.pos-b]=f[now.pos];
				pq.push(make_node(now.pos-b,f[now.pos-b]));
			}
		}
		if(now.pos+a<=a+b){
			if(f[now.pos+a]>max(f[now.pos],now.pos+a)){
				f[now.pos+a]=max(f[now.pos],now.pos+a);
				pq.push(make_node(now.pos+a,f[now.pos+a]));
			}
		}
	}
	for(register int i=0,j=0;i<=m;++i,++j){
		if(j==a)j=0;
		ans+=max(0,m-max(i,f[j])+1);
	}
	printf("%I64d",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x) return x<a.x;
        return y<a.y;
    }
};

long long x,y,z,mod=1000000007;
vector<int> v;
int i,n,m,k,a,d,b,c;
int e;
int o[531111];
int l[531112];
int j[1];

priority_queue<int,vector<int>,greater<int> > q;
queue<P> q1;
P u[1];

char r[1],r1[3];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();

bool as(P a,P b)
{
    return a.x<b.x;
}

int f(int n,int m)
{
    int k=0;
    for(;n<m;)
    {
        if(n%2) k+=o[n],n++;
        else if(m%2==0) k+=o[m],m--;
        else n/=2,m/=2;
    }
    return k+o[n];
}

int main()
{
    scanf("%d %d %d",&c,&a,&b);
    q.push(a);
    e=a;
    for(i=1;i<a+b;i*=2);
    for(;q.size();)
    if(q.top()<=a+b)
    {
        //printf("@@%d %d\n",q.top(),e);
        e=max(e,q.top());
        int d=q.top();
        if(d>b&&o[d-b+i-1]==0)
        {
            //puts("#");
            //for(int h=(d-b+i-1);h>0;h/=2)
              //  o[h]++;
            q.push(d-b);
            goto qwe;
        }
        for(int h=(d+i-1);h>0;h/=2)
            o[h]++;
        if(e==d)
        {
            //printf("$$$%d\n",f(i,d+i-1)+1);
            l[d]=f(i,d+i-1)+1;
        }
        q.pop();
        if(o[d+a+i-1]==0)
            q.push(d+a);
        qwe:;
    }
    else q.pop();
    l[0]=1;
    x=1;
    for(int t=1;t<a+b;t++)
    {
        if(l[t]==0) l[t]=l[t-1];
        if(t<=c) x+=l[t];
        //printf("%d ",l[t]);
    }
    k=__gcd(a,b);
    if(c>=a+b)
    for(;c%k!=k-1;c--)
        x+=c/k+1;
    if(a+b<=c)
    //x+=(long long)(c+a+b+2)*(c-a-b+1)/2;
        x+=(long long)(c/k+(a+b)/k)*k*(c-a-b+1)/k/2+(c-a-b+1);
    printf("%lld",x);
}

#include <stdio.h>
const int C=2*100001;
int dp[C];
long long csc[C];

int main(){
	long long n, a, v=0, gcd=1000000, mx=0, b, summa=0, w1, w2, art=0, a1, an, t, s, sp, ep, ep2, m;
	int i=0, j=0;
	scanf ("%lld %lld %lld", &n, &a, &b);
	v=a;
	while (dp[v]==0 && v>0){
		if (gcd>v && v>0) gcd=v;
		if (mx<v) mx=v;
		dp[v]=mx;
		if (v>=b) v-=b;
		else v+=a;
	}
	for (i=1;i<a+b;i++) if (dp[i]!=0) csc[dp[i]]+=1;
	csc[0]++;
	summa+=csc[0];
	for (i=1;i<a+b && i<=n;i++){
		csc[i]+=csc[i-1];
		summa+=csc[i];
	}

	s=(a+b)/gcd;
	sp=(s+1)*gcd;
	if (sp>n) sp=n+1;
	w1=(sp-(a+b))*(s+1);

	t=n/gcd;
	ep=(t-1)*gcd;
	ep2=t*gcd;
	w2=(n-ep2+1)*(t+1);
	a1=s+1+1;
	an=t-1+1;
	m=an-a1+1;
	if (m>0) art=(((a1+an)*m)/2)*gcd;
	else art=0;
	if (n>=a+b){
		summa+=w1+art;
		if (s<t) summa+=w2;
	}

	printf ("%lld\n", summa);
	//printf ("sum:%lld art:%lld %lld w1:%lld w2:%lld a1:%lld an:%lld\n", summa, art, s, w1, w2, a1, an);
return 0;}

#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int inf = (~0u >> 2);

#define ll long long

typedef class Node {
	public:
		int p, d;

		Node(int p, int d) : p(p), d(d) {	}

		boolean operator < (Node b) const {
			return d > b.d;
		}
} Node;

int m, a, b;
int f[100005];

ll s2(int n) {
	return 1ll * n * (n + 1) / 2;
}

int main() {
	scanf("%d%d%d", &m, &a, &b);
	for (int i = 0; i < a; i++)
		f[i] = inf;
	priority_queue<Node> Q;
	Q.push(Node(0, f[0] = 0));
	while (!Q.empty()) {
		int p = Q.top().p;
		int d = Q.top().d;
		Q.pop();
		if (d ^ f[p]) {
			continue;
		}
		int e = (((p - b) % a) + a) % a;
		int k = max(max((b + a - 1 - p) / a, 0) * a + p, d);
		if (k < f[e]) {
			Q.push(Node(e, f[e] = k));
		}
	}
	ll ans = 0;
	for (int i = 0; i < a; i++) {
		if (f[i] <= m) {
			int c = (f[i] - i) / a + 1;
			int R = (m - i) / a;
			ans += 1ll * c * (m - f[i] + 1);
			ans += 1ll * (R - c + 1) * (m - i + 1);
			ans -= 1ll * a * (s2(R) - s2(c - 1));
		}
	}
	printf("%lld\n", ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define double long double
#define int long long
#define vec vector
#define pb push_back
#define unset unordered_set
#define ii pair<int, int>
#define X first
#define Y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first,l.second+r.second};
}
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

// If I need to find (x / a) % b, I need to use this function:
//    (x / a) % b = (x * inv(a, b)) % b
ll inv(ll a, ll b) {
  if (a != 1) {
    return b - (inv(b % a, a) * b) / a;
  }
  return 1;
}

inline int Pow(int a, int k) {
  int s = 1;
  for(; k; k >>= 1) {
    k & 1 ? s = 1LL * s * a % MOD : 0;
    a = 1LL * a * a % MOD;
  }
  return s;
}

// Init variables here
const int N = 1e6 + 7;

void input() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);
}

void output() {

}

void preprocess() {

}

void debug() {
  if (true) {

  }
}

void solve() {
  preprocess();
  int m, a, b;
  cin >> m >> a >> b;
  int n = a + b;
  vec<int> firstPos(n, INF32); // firstPos[i] = j iff i is reachable in interval
                               //               [0..j] and j is minimal
                               //               or INF if unreachable
  int curPos = 0, maxPos = 0;
  do {
    firstPos[curPos] = maxPos;
    if (curPos >= b) {curPos -= b;}
    else {curPos += a;}
    maxPos = max(maxPos, curPos);
  } while (curPos);
  int res = 0;
  FOR(i, 0, n) {res += max(0LL, m - firstPos[i] + 1);}
  if (m >= n) {
    int remaining = m - n;
    int gcd = __gcd(a, b);
    int mx = remaining + 1;
    int mn = remaining % gcd + 1;
    int cnt = (mx - mn) / gcd + 1;
    res += (mx + mn) * cnt / 2;
  }
  cout << res << endl;
  //debug();
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

#undef int
int main() {
#define int long long
  ios_base::sync_with_stdio(false);
  cin.tie();
  //auto beginProgram = chrono::steady_clock::now();

  //int t; cin >> t;
  //while (t--)
  {
    input();
    solve();
    output();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}

/** Header .. **/ //{
#define LOCAL

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )

#define ALL(A) A.begin(), A.end()
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)
#define fi first
#define se second

#define Rush for(int ____T=RD(); ____T--;)

#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize ("O2")
#define Ruby system("ruby main.rb")
#define Haskell system("runghc main.hs")
#define Python system("python main.py")
#define Pascal system("fpc main.pas")

typedef long long LL;
//typedef long double DB;
typedef double DB;
typedef unsigned UINT;
typedef unsigned long long ULL;
typedef pair<int , int> PII;

typedef vector<int> VI;
template<class T> inline T& RD(T &);
template<class T> inline void OT(const T &);
inline LL RD(){LL x; return RD(x);}
inline DB& RF(DB &);
inline DB RF(){DB x; return RF(x);}
inline char* RS(char *s);

template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}

template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}

template<class T> inline T& SRT(T &A){sort(ALL(A)); return A;}
template<class T, class C> inline T& SRT(T &A, C B){sort(ALL(A), B); return A;}
template<class T> inline T& UNQ(T &A){A.resize(unique(ALL(SRT(A)))-A.begin());return A;}

//}

/** Constant List .. **/ //{

const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};

const int dx8[] = {-1, 0, 1, 0 , -1 , -1 , 1 , 1};
const int dy8[] = {0, 1, 0, -1 , -1 , 1 , -1 , 1};

const int dxhorse[] = {-2 , -2 , -1 , -1 , 1 , 1 , 2 , 2};
const int dyhorse[] = {1 ,  -1 , 2  , -2 , 2 ,-2 , 1 ,-1};

const int MOD = 1000000007;
//int MOD = 99990001;
const int INF = 0x3f3f3f3f;
const LL INFF = 1LL << 60;
const DB EPS = 1e-9;
const DB OO = 1e15;
const DB PI = acos(-1.0); //M_PI;

//}

/** Add On .. **/ //{
// <<= '0. Nichi Joo ., //{
template<class T> inline void checkMin(T &a,const T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a,const T b){if (a<b) a=b;}
template<class T> inline void checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);}
template<class T> inline void checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);}
template <class T, class C> inline void checkMin(T& a, const T b, C c){if (c(b,a)) a = b;}
template <class T, class C> inline void checkMax(T& a, const T b, C c){if (c(a,b)) a = b;}
template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T cub(T a){return a*a*a;}
inline int ceil(int x, int y){return (x - 1) / y + 1;}
inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
inline int sgn(DB x, DB y){return sgn(x - y);}
//}
// <<= '1. Bitwise Operation ., //{
namespace BO{

inline bool _1(int x, int i){return bool(x&1<<i);}
inline bool _1(LL x, int i){return bool(x&1LL<<i);}
inline LL _1(int i){return 1LL<<i;}

template<class T> inline bool odd(T x){return x&1;}
template<class T> inline bool even(T x){return !odd(x);}
template<class T> inline T low_bit(T x) {return x & -x;}
inline int count_bits(int x){return __builtin_popcount(x);}
inline int count_bits(LL x){return __builtin_popcountll(x);}

} using namespace BO;//}
// <<= '2. Number Theory .,//{
namespace NT{
//inline LL __lcm(LL a, LL b){return a*b/__gcd(a,b);}
inline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;}
inline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;}
inline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;}
inline int dff(int a, int b){a -= b; if (a < 0) a  += MOD; return a;}
inline void MUL(int &a, int b){a = (LL)a * b % MOD;}
inline int pdt(int a, int b){return (LL)a * b % MOD;}

inline int sum(int a, int b, int c){return sum(sum(a, b), c);}
inline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));}
inline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);}
inline int pdt(int a, int b, int c, int d){return pdt(pdt(pdt(a, b), c), d);}

inline int pow(int a, int b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

inline int pow(int a, LL b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

template<class T> inline T pow(T a, LL b){
    T c(1); while (b){
        if (b&1) c *= a;
        a *= a, b >>= 1;
    }
    return c;
}

inline int _I(int b){
    int a = MOD, x1 = 0, x2 = 1, q;
    while (true){
        q = a / b, a %= b;
        if (!a) return (x2 + MOD) % MOD;
        DEC(x1, pdt(q, x2));

        q = b / a, b %= a;
        if (!b) return (x1 + MOD) % MOD;
        DEC(x2, pdt(q, x1));
    }
}

inline void DIV(int &a, int b){MUL(a, _I(b));}
inline int qtt(int a, int b){return pdt(a, _I(b));}

inline int phi(int n){
    int res = n; for (int i=2;sqr(i)<=n;++i) if (!(n%i)){
        DEC(res, qtt(res, i));
        do{n /= i;} while(!(n%i));
    }
    if (n != 1)
        DEC(res, qtt(res, n));
    return res;
}

} using namespace NT;//}
//}

//}
//}

/** Algorithm    .. */ //{
// <<= '-. Math .,//{

namespace Math{
	typedef long long typec;
	///Lib functions
	typec GCD(typec a, typec b)
	{
		return b ? GCD(b, a % b) : a;
	}
	typec extendGCD(typec a, typec b, typec& x, typec& y)
	{
		if(!b) return x = 1, y = 0, a;
		typec res = extendGCD(b, a % b, x, y), tmp = x;
		x = y, y = tmp - (a / b) * y;
		return res;
	}
	///for x^k
	typec power(typec x, typec k)
	{
		typec res = 1;
		while(k)
		{
			if(k&1) res *= x;
			x *= x, k >>= 1;
		}
		return res;
	}
	///for x^k mod m
	typec powerMod(typec x, typec k, typec m)
	{
		typec res = 1;
		while(x %= m, k)
		{
			if(k&1) res *= x, res %= m;
			x *= x, k >>=1;
		}
		return res;
	}
	/***************************************
	Inverse in mod p^t system
	***************************************/
	typec inverse(typec a, typec p, typec t = 1)
	{
		typec pt = power(p, t);
		typec x, y;
	    y = extendGCD(a, pt, x, y);
		return x < 0 ? x += pt : x;
	}
	/***************************************
	Linear congruence theorem
	x = a (mod p)
	x = b (mod q)
	for gcd(p, q) = 1, 0 <= x < pq
	***************************************/
	typec linearCongruence(typec a, typec b, typec p, typec q)
	{
		typec x, y;
		y = extendGCD(p, q, x, y);
		while(b < a) b += q / y;
		x *= b - a, x = p * x + a, x %= p * q;
		if(x < 0) x += p * q;
		return x;
	}
	/***************************************
	prime table
	O(n)
	***************************************/
	const int PRIMERANGE = 1000000;
	int prime[PRIMERANGE + 1];
	int getPrime()
	{
		memset (prime, 0, sizeof (int) * (PRIMERANGE + 1));
		for (int i = 2; i <= PRIMERANGE; i++)
		{
			if (!prime[i]) prime[++prime[0]] = i;
			for (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++)
			{
				prime[prime[j]*i] = 1;
				if (i % prime[j] == 0) break;
			}
		}
		return prime[0];
	}
	/***************************************
	get factor of n
	O(sqrt(n))
	factor[][0] is prime factor
	factor[][1] is factor generated by this prime
	factor[][2] is factor counter

	need: Prime Table
	***************************************/
	///you should init the prime table before
	int factor[100][3], facCnt;
	int getFactors(int x)
	{
		facCnt = 0;
		int tmp = x;
		for(int i = 1; prime[i] <= tmp / prime[i]; i++)
		{
			factor[facCnt][1] = 1, factor[facCnt][2] = 0;
			if(tmp % prime[i] == 0)
				factor[facCnt][0] = prime[i];
			while(tmp % prime[i] == 0)
				factor[facCnt][2]++, factor[facCnt][1] *= prime[i], tmp /= prime[i];
			if(factor[facCnt][1] > 1) facCnt++;
		}
		if(tmp != 1)
			factor[facCnt][0] = tmp, factor[facCnt][1] = tmp, factor[facCnt++][2] = 1;
		return facCnt;
	}
	typec combinationModP(typec n, typec k, typec p)
	{
		if(k > n) return 0;
		if(n - k < k) k = n - k;
		typec a = 1, b = 1, x, y;
		int pcnt = 0;
		for(int i = 1; i <= k; i++)
		{
			x = n - i + 1, y = i;
			while(x % p == 0) x /= p, pcnt++;
			while(y % p == 0) y /= p, pcnt--;
			x %= p, y %= p, a *= x, b *= y;
			b %= p, a %= p;
		}
		if(pcnt) return 0;
		extendGCD(b, p, x, y);
		if(x < 0) x += p;
		a *= x, a %= p;
		return a;
	}
};//using namespace Math;
//}
// <<= '-. Geo ,.//{
namespace Geo{
	#define typec double
    const typec eps=1e-8;
    int dblcmp(double d){
        return d < -eps ? -1 : d > eps;
    }
    int sgn(double a) {return a<-eps?-1:a>eps;}
    inline double sqr(double x){return x*x;}
};//using namespace Geo;
//}
//}
/*
namespace IO {
    const int MT = 100 * 1024 * 1024;  /// 10MB 请注意输入数据的大小！！！
    char IO_BUF[MT];
    int IO_PTR, IO_SZ;
    /// 要记得把这一行添加到main函数第一行！！！
    void begin() {
        IO_PTR = 0;
        IO_SZ = fread (IO_BUF, 1, MT, stdin);
    }
    template<typename T>
    inline bool scan_d (T & t) {
        while (IO_PTR < IO_SZ && IO_BUF[IO_PTR] != '-' && (IO_BUF[IO_PTR] < '0' || IO_BUF[IO_PTR] > '9'))
            IO_PTR ++;
        if (IO_PTR >= IO_SZ) return false;
        bool sgn = false;
        if (IO_BUF[IO_PTR] == '-') sgn = true, IO_PTR ++;
        for (t = 0; IO_PTR < IO_SZ && '0' <= IO_BUF[IO_PTR] && IO_BUF[IO_PTR] <= '9'; IO_PTR ++)
            t = t * 10 + IO_BUF[IO_PTR] - '0';
        if (sgn) t = -t;
        return true;
    }
    inline bool scan_s (char s[]) {
        while (IO_PTR < IO_SZ && (IO_BUF[IO_PTR] == ' ' || IO_BUF[IO_PTR] == '\n') ) IO_PTR ++;
        if (IO_PTR >= IO_SZ) return false;
        int len = 0;
        while (IO_PTR < IO_SZ && IO_BUF[IO_PTR] != ' ' && IO_BUF[IO_PTR] != '\n')
            s[len ++] = IO_BUF[IO_PTR], IO_PTR ++;
        s[len] = '\0';
        return true;
    }
    template<typename T>
    void print(T x) {
        static char s[33], *s1; s1 = s;
        if (!x) *s1++ = '0';
        if (x < 0) putchar('-'), x = -x;
        while(x) *s1++ = (x % 10 + '0'), x /= 10;
        while(s1-- != s) putchar(*s1);
    }
    template<typename T>
    void println(T x) {
        print(x); putchar('\n');
    }
};
*/
/** I/O Accelerator Interface .. **/ //{
template<class T> inline T& RD(T &x){
    //cin >> x;
    //scanf("%d", &x);
    char c; for (c = getchar(); c < '-'; c = getchar());
    if (c == '-'){x = '0' - getchar(); for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + '0' - c;}
    else {x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';}
    return x;
}

inline DB& RF(DB &x){
    //cin >> x;
    scanf("%lf", &x);
    /*char t; while ((t=getchar())==' '||t=='\n'); x = t - '0';
    while ((t=getchar())!=' '&&t!='\n'&&t!='.')x*=10,x+=t-'0';
    if (t=='.'){DB l=1; while ((t=getchar())!=' '&&t!='\n')l*=0.1,x += (t-'0')*l;}*/
    return x;
}

inline char* RS(char *s){
    //gets(s);
    scanf("%s", s);
    return s;
}

int Case; template<class T> inline void OT(const T &x){
    //printf("Case %d: %d\n", ++Case, x);
    //printf("%.2lf\n", x);
    //printf("%d\n", x);
    cout << x << endl;
}
//}

/* .................................................................................................................................. */
LL f(LL m , LL r){
    LL p = m / r;
    p *= r;
    LL x = p / r;
    LL ret = (1 + x) * x / 2 * r;
    //cout << "= " << x << ' ' << r << ' ' << ret << endl;
    while(p <= m){
        ret += p / r + 1;
        //cout << p << ' ' << p / r << ' ' << ret << endl;
        ++p;
    }
    return ret;
}

LL m , a , b;
priority_queue<LL> q;
void solve(){
    LL r = Math::GCD(a , b);
    int cc = 1;
    LL hold = a;
    int p = 1;
    LL ans = 1;
    LL cur = 1;
    while(cc < a / r && p <= m){
        if (p < hold){
            ans += cur;
            ++p;
            continue;
        }
        while(p >= hold){
            while(hold > 0){
                if (hold < a) ++cc;
                cur++;
                q.push(-hold);
                hold -= b;
            }
                hold = -q.top() + a;
                q.pop();
        }
        ans += cur;
        ++p;
    }
    //cout << "DEBUG " << p << ' ' << ans << endl;
    if (p <= m){
        ans += f(m , r) - f(p - 1 , r);
    }
    OT(ans);
}
int main(){
    while (cin >> m >> a >> b) solve();
}

// D. Frog Jumping
#include <bits/stdc++.h>

using namespace std;

#define	INF	2000000000

int main(int argc, char *argv[])
{
	int m, a, b;
	cin >> m >> a >> b;

	int n = min(m, a + b - 1), g = __gcd(a, b);
	vector<int> d(n + 1, n + 1);
	vector<long long> sum(n + 1);
	set<pair<int, int> > s;
	s.insert(make_pair(0, 0));
	d[0] = 0;
	while (!s.empty()) {
		int i = s.begin()->first, j = s.begin()->second;
		s.erase(s.begin());
		if (d[j] != i) continue;
		sum[i]++;
		if (j >= b && i < d[j - b]) {
			d[j - b] = i;
			s.insert(make_pair(i, j - b));
		}
		if (j + a <= n && max(i, j + a) < d[j + a]) {
			d[j + a] = max(i, j + a);
			s.insert(make_pair(max(i, j + a), j + a));
		}
	}

	// for (int i = 0; i < d.size() && i < 30; i++) printf("d[%d] %d ", i, d[i]); printf("\n");
	// for (int i = 0; i < d.size() && i < 30; i++) printf("s[%d] %d ", i, (int) sum[i]); printf("\n");

	long long ans = 0;
	for (int i = 0; i <= n; i++) {
		if (i > 0) sum[i] += sum[i - 1];
		ans += sum[i];
	}
	if (n != m) {
		for ( ; (m + 1) % g; m--) ans += m / g + 1;
		long long n1 = n / g + 1, n2 = m / g + 1;
		ans += (n2 * (n2 + 1) / 2 - n1 * (n1 + 1) / 2) * g;
	}

	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int gcd(int a, int b)
{
	while (a)
	{
		int tmp = b%a;
		b = a;
		a = tmp;
	}
	return b;
}

int dist[200007]; // d_i
ll sum[200007];

int main()
{
	int m, a, b;
	scanf("%d%d%d", &m, &a, &b);
	int n = min(m, a + b - 1);
	for (int i = 0; i <= n; i++)
		dist[i] = n + 1;

	set <pii> s; // x, d_i
	s.insert({ 0, 0 });
	dist[0] = 0;
	while (!s.empty())
	{
		pii tmp = *s.begin();
		s.erase(s.begin());
		if (dist[tmp.second] != tmp.first) // 왜 필요하죠?
			continue;
		sum[tmp.first]++; // d_i가 tmp.first인 모든 노드의 개수

		//b~a+b 까지 반복이므로 일단 0~a+b까지 구한다. (dp)
		if (tmp.second >= b && tmp.first < dist[tmp.second - b])
		{
			dist[tmp.second - b] = tmp.first;
			s.insert({ tmp.first, tmp.second - b });
		}
		if (tmp.second + a <= n && max(tmp.first, tmp.second + a) < dist[tmp.second + a])
		{
			dist[tmp.second + a] = max(tmp.first, tmp.second + a);
			s.insert({ max(tmp.first, tmp.second + a), tmp.second + a });
		}
	}

	ll ans = 0;
	for (int i = 0; i <= n; i++)
	{
		if (i > 0)
			sum[i] += sum[i - 1];
		ans += sum[i];
	}
	//여기까지 0~n까지의 합을 구했다.

	//이제 m까지를 구해보자...
	ll g = (ll)gcd(a, b);
	if (m > n)
	{
		ll tmp = m;
		while ((tmp + 1) % g) tmp--;

		ans += ((ll)m - tmp)*((ll)m / g + 1);
		ans += ((((ll)tmp / g + 1)*((ll)tmp / g + 2) / 2) - (((ll)n / g + 1)*((ll)n / g + 2) / 2)) * g;
	}

	printf("%lld", ans);
}

#include<bits/stdc++.h>

using namespace std;

int main(){
	int m,a,b;
	cin >> m >> a >> b;

	long long res=m+1,x=a,y=a,g=__gcd(a,b);
	while(x){
		if(m>=y) res+=m-y+1;
		x+=(x<b?a:-b);
		if(x>y) y=x;
	}
	m-=a+b;
	res+=(m<0?0:(m+m%g+2)*(m/g+1)/2);
	cout << res;
	return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
const int mod=1000000007;
const int inf=1000000009;
const long long int INF=1000000000000000009;
const long double eps=0.0000000001;
using namespace std;
bool O[200005];
int numer=0;
ll wynik=0;
int aktual=1;
int a,b;
void dfs(int n)
{
    O[n]=1;
    aktual++;
    if(n+a<=numer&&!O[n+a])
        dfs(n+a);
    if(n-b>=0&&!O[n-b])
        dfs(n-b);
}
int main()
{
    int m;
    scanf("%d %d %d",&m,&a,&b);
    wynik++;
    O[0]=true;
    for(int i=1;i<=min(m,a+b-1);i++)
    {
        numer=i;
        if(i-a>=0&&O[i-a])
            dfs(i);
        wynik+=aktual;
       // printf("%d %d %lld\n",i,aktual,wynik);
    }
    if(m<a+b)
    {
        printf("%lld",wynik);
        return 0;
    }
    ll g=__gcd(a,b);
    ll a1=g*((a+b)/g+1);
    ll l=(m-a-b+1)/g;
    ll an=a1+(l-1)*g;
    wynik+=(a1+an)*l/2;
    an+=g;
    an/=g;
    wynik+=an*((m-a-b+1)%g);
    printf("%lld",wynik);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 5e6;

int m, a, b;
bitset<N + 1> used;
long long res = 0;
int sz;
set<int> nxt;

int go(int u, int base) {
    // cout << u << ' ' << base << endl;
    used[u] = 1;
    res += m + 1 - base;
    int ans = 1e9;
    if (u >= b && used[u - b] == 0) {
        int foo = go(u - b, base);
        ans = min(ans, foo);
    }
    if (u + a <= base && used[u + a] == 0) {
        int foo = go(u + a, base);
        ans = min(ans, foo);
    }
    if (u + a > base) {
        ans = min(ans, u + a);
        nxt.insert(u + a);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> m >> a >> b;
    int cur = 0;
    sz = min(m, N);
    while (1) {
        go(cur, cur);
        if (nxt.size() == 0) break;
        int id = *nxt.begin();
        nxt.erase(nxt.begin());
        if (id > sz) break;
        cur = id;
    }
    int cnt = 0;
    if (m > N) {
        int foo = __gcd(a, b);
        int num = (m - cur) / foo;
        res += 1ll * (m + 1) * num;
        long long now = 1ll * num * cur;
        long long bar = 1ll * num * (num + 1) / 2;
        now += 1ll * foo * bar;
        res -= now;
    }
    cout << res << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=300000;
long long n,m,a,b,x;
long long ans=0;
bool f[maxn+5];
long long an[maxn+5];
queue<long long>q;
long long calc(long long x)
{
    return x*(x+1)>>1;
}
long long calc2(long long x,long long mo)
{
    if(x % mo == 0) return x/mo;
    else return x/mo+1;
}
long long dzc(long long n)
{
    return calc((n+1)/x)*x+((n+1)%x)*(calc2(n+1,x));
}
long long gcd(long long x,long long y)
{
    if(x%y!=0) return gcd(y,x%y);
    return y;
}
long long bfs(long long i)
{
    long long ans=0;
    f[0]=1;
    while(!q.empty())
	{
        int x=q.front();
        q.pop();
        ans++;
        if(x+a<=i and !f[x+a])  f[x+a]=1,q.push(x+a);
        if(x-b>=0 and !f[x-b])  f[x-b]=1,q.push(x-b);
    }
    return ans;
}
int main()
{
	ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    x=gcd(a,b);
    q.push(0);
    an[0]=1;
    f[0]=1;
    bfs(0);
    for(long long i=1;i<=max(a,b)*2;i++)
	{
        if(i-a>=0 and f[i-a])
		{
            f[i]=1;
            q.push(i);
            an[i]=an[i-1]+bfs(i);
        }
		else  an[i]=an[i-1];
    }
    if(a>b)
      swap(a,b);
        for(int i=0;i<min(n+1,2*b);i++)
		{
            ans+=an[i];
        }
        if(n>=2*b)
            ans+=dzc(n)-dzc(2*b-1);

    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef pair<int, int> int2;
#define pp(a,b) push_back(make_pair((a),(b)))
#define pb push_back
#define mp make_pair
#define buybuy {printf("-1\n");return 0;}
#define PI 3.141592653589

int next() {int x; cin >> x; return x;}
lint lnext() {lint x; cin >> x; return x;}
//template<typename T> outln(T x) {cout << x; cout << "\n";}
#define prt(a) cout << a << "\n";
#define prtn(a, n) {for(int iiiiiiiiiii = 0; iiiiiiiiiii < n; iiiiiiiiiii++) cout << a[iiiiiiiiiii] << " "; cout << "\n";}
#define prtall(a) {for (auto iiiiiiiiiii : a) cout << iiiiiiiiiii << " "; cout << "\n";}

int gcd(int x, int y) {
	if (!x || !y) return x + y;
	return gcd(y % x, x);
}

int main() {
	cout.precision(20);
	ios_base::sync_with_stdio(false);

	lint m = next();
	lint a = next();
	lint b = next();

	lint inf = (int)(1e9 + 1);

	int l = max(a, b) + 1;
	vector<lint> mn(l, inf);
	mn[0] = 0;

	for (int i = 1;; i++) {
		if (i * a % b == 0) mn[b] = max(mn[(i - 1) * a % b], (i - 1) * a % b + a);
		if (mn[i * a % b] != inf) break;
		mn[i * a % b] = max(mn[(i - 1) * a % b], (i - 1) * a % b + a);
	}

	//prtn(mn, l);

	for (int i = b + 1; i < a; i++) mn[i] = mn[i - b];

	//prtn(mn, l);

	lint answ = 0;
	for (lint i = 0; i < a; i++) if (mn[i] != inf) {
		lint r = (mn[i] - i) / a;
		lint k = (m - i) / a;

		answ += max(0ll, (r + 1) * (m - mn[i] + 1));

		if (k > r) {
			answ += (k - r) * ((m - (i + (r + 1)* a) + 1) + (m - (i + k * a) + 1)) / 2;
		}

		//cout << "answ after " << i << ": " << answ << "\n";
	}

	cout << answ << "\n";
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e5+5;
ll cnt[N],sum[N];
bool vis[N];
ll gcd(ll a,ll b){
	if(a%b==0)
		return b;
	return gcd(b,a%b);
}
priority_queue<pii,vector<pii>,greater<pii>>q;
int main()
{
	ll m,a,b;
	cin>>m>>a>>b;
	q.push(pii(0,0));
	ll mx=min(a+b-1,m);
	while(!q.empty()){
		ll pre=q.top().fi;
		ll now=q.top().se;
		q.pop();
		cnt[pre]++;
		if(now-b>0&&!vis[now-b]){
			q.push(pii(pre,now-b));
			vis[now-b]=true;
		}
		if(now+a<=mx&&!vis[now+a]){
			q.push(pii(max(now+a,pre),now+a));
			vis[now+a]=true;
		}
	}

//	rep(i,0,mx+1)
//		de(cnt[i])
	sum[0]=cnt[0];
	ll ans=sum[0];
	rep(i,1,mx+1){
		sum[i]=sum[i-1]+cnt[i];
		ans+=sum[i];
	}

	if(mx<m){
		ll g=gcd(a,b);
		while(m>=mx&&(m+1)%g){
			ans+=m/g+1;
			m--;
		}
		mx++;
		ll l=mx/g+1,r=m/g+1;
		ans+=(r-l+1)*(r+l)/2*g;

	}
	cout<<ans<<endl;
	return 0;
}

/////////////////////////   _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 + 3;

int m , a , b;

int gcd(int a,int b){
    if(b == 0)return a;
    return gcd(b , a % b);
}

int f[N];
bool used[N];

set <int> q;

int main() {
	mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> m >> a >> b;
    int g = gcd(a , b);
    int n = a + b - g;
    used[0] = true;
    q.insert(0);
    int x = 0;
    while(!q.empty()){
        int v = (*q.begin());
        q.erase(q.begin());
        x = max(x , v);
        f[x]++;
        if(v + a <= n && used[v + a] == false){
            used[v + a] = true;
            q.insert(v + a);
        }
        if(v - b >= 0 && used[v - b] == false){
            used[v - b] = true;
            q.insert(v - b);
        }
    }
    long long answ = 0 , s = 0;
    n = min(n , m);
    for(int i=0;i<=n;i++){
        s += f[i];
        answ += s;
    }
    if(m <= n){
        cout << answ << endl;
        return 0;
    }
    if(m - n < g){
        m -= n;
        answ += m * 1ll * s;
        cout << answ << endl;
        return 0;
    }
    m -= n + g - 1;
    answ += (g - 1) * 1ll * s;
    ++s;
    long long sz = m / g;
    if(sz){
        answ += g * 1ll * (2 * s + sz - 1) * 1ll * sz / 2;
    }
    m %= g;
    while(m--){
        answ += s + sz;
    }
    cout << answ << endl;
	return 0;
}

#include<bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=1e5+5;
int dp[MAXN<<1];
bool vis[MAXN<<1];
ll get(int x,int g)
{
	ll ret=0;
	int lim=x/g-1;
	int st=(lim+1)*g;
	ret=1LL*(x-st+1)*(lim+1)+1LL*(1+lim)*(lim)/2*g+x+1;
	return ret;
}
ll solve(int l,int r,int g)
{
	if(l>r) return 0;
	ll ret=get(r,g)-get(l-1,g);
	return ret;
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int m,a,b,n;
	scanf("%d%d%d",&m,&a,&b);
	n=max(a,b)*2;
	dp[0]=1;vis[0]=true;
	for(int i=1;i<n;i++)
	{
		dp[i]=dp[i-1];
		if(i-a>=0&&vis[i-a])
		{
			queue<int> Q;
			Q.push(i);
			dp[i]++;vis[i]=true;
			while(!Q.empty())
			{
				int now=Q.front();
				Q.pop();
				if(now-b>=0&&!vis[now-b])
				{
					dp[i]++;
					vis[now-b]=true;
					Q.push(now-b);
				}
				if(now+a<=i&&!vis[now+a])
				{
					dp[i]++;
					vis[now+a]=true;
					Q.push(now+a);
				}
			}
		}
		//cout<<i<<" "<<dp[i]<<endl;
	}
	ll ans=0;
	for(int i=0;i<min(n,m+1);i++)
		ans+=dp[i];
	ans+=solve(n,m,__gcd(a,b));
	printf("%lld\n",ans);
	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
const int MX = 1000005;
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
		return gcd(b, a%b);
}
ll m, a, b, g, start, vis[MX], mx, ans, c, s[MX], p[MX], q;
ll calc(ll x, ll m)
{
	m -= x;
	if (m < 0)return 0;
	if (m == 0)return 1;
	return (m + 1)*(m / a + 1) - a * (m / a)*(m / a + 1) / 2;
}
int main() {
	cin >> m >> a >> b;
	g = gcd(a, b);
	vis[0] = 1;
	while (true) {
		if (start < b) {
			start += a;
		}
		else {
			mx = max(mx, start);
			start -= b;
			if (vis[start]) {
				break;
			}
			p[start] = mx;
			vis[start] = 1;
		}
	}
	for (ll i = 0; i < a; i += g) {
		for (ll j = i; j <= min(mx, m); j += a) {
			s[max(j, p[i])] += 1;
		}
	}
	for (int i = 0; i < a; i+=g) {
		if (m < p[i]) continue;
		ans += calc(i, m) - calc(i, p[i] - 1);
	}
	cout << ans;
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
string toString(long long x)
{
stringstream ss;
ss << x;
string str = ss.str();
return str;
}
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
const long long MX = 2651120;
long long n,a,b;
bitset<MX+5> reachable;
long long sumR(long long r)
{
    return (r * (r + 1)) / 2;
}
vector<int> edgeList[MX+5];
int ingoing[MX+5];
long long removeChild(int idx)
{
    if(idx == 0)
        return 0;
    long long C = 1;
    reachable[idx] = false;
    for(int i = 0;i < edgeList[idx].size();i++)
    {
        if(!reachable[edgeList[idx][i]])
            continue;
        ingoing[edgeList[idx][i]]--;
        if(ingoing[edgeList[idx][i]] == 0 && reachable[edgeList[idx][i]])
            C += removeChild(edgeList[idx][i]);
    }
    return C;
}
int main()
{
    IO;
    cin >> n >> a >> b;
    long long f1 = 0;
    long long c = 0;
    long long temp = 0;
    for(int i = 0;i <= min(n,MX);i++)
    {
        if(i + a <= min(n,MX))
            edgeList[i].push_back(i+a),ingoing[i+a]++;
        if(i - b >= 0)
            edgeList[i].push_back(i-b),ingoing[i-b]++;
    }
    queue<int> myQue;
    myQue.push(0);
    while(!myQue.empty())
    {
        int tt = myQue.front();
        //cout << tt << endl;
        myQue.pop();
         //       cout << tt << endl;
        if(reachable[tt])
            continue;
        reachable[tt] = true;
        temp++;
        if(tt + a <= min(n,MX) && !reachable[tt + a])
            myQue.push(tt+a);
        if(tt - b >= 0 && !reachable[tt - b])
            myQue.push(tt-b);
    }
    //cout << temp << endl;
    for(int i = min(n,MX);i >= 0;i--)
    {
        f1 += temp;
        if(!reachable[i])
            continue;
        temp -= removeChild(i);
    }
    c = min(n+1,MX+1);
    long long len = n - c + 1;
    long long firstStart = MX+1;
    long long lastEnd = n;
    if(firstStart > lastEnd)
    {
        cout <<f1;
        return 0;
    }
    long long s2 = 0;
    int gcd = __gcd(a,b);
    while(firstStart % gcd != 0 && firstStart <= lastEnd)
        s2 += firstStart/gcd,firstStart++;
   // cout << s2 << endl;
    long long inBetween = (lastEnd-firstStart) / gcd;
    //cout << sumR((firstStart / gcd) + (inBetween - 1)) << " " << sumR((firstStart / gcd) - 1) << endl;
    s2 += (sumR((firstStart / gcd) + (inBetween - 1)) - sumR((firstStart / gcd) - 1)) * gcd;
    //cout << s2 << endl;
    firstStart += gcd*inBetween;
    while(firstStart <= lastEnd)
        s2 += firstStart/gcd,firstStart++;
    //cout << s2 << endl;
    cout << f1 + s2 + len;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
const ll INF=LLONG_MAX,MOD=1e9+7;
const int L=17,N=1<<L;

ll d[1111111];
ll m,a,b;

ll gcd(ll x,ll y){
	if(y==0){
		return x;
	}
	return gcd(y,x%y);
}

ll som(ll x, ll y, ll g){
	return (x+y)*((y-x)/g+1)/2;
}

ll fill(ll k, ll i){
	ll cnt=1;
	d[k]=i;
	// cout << k << " "<<i <<endl;
	if(k-b>=0 && (d[k-b]==m+1)){
		cnt+=fill(k-b,i);
	}
	if(k+a<=i && (d[k+a]==m+1)){
		cnt+=fill(k+a,i);
	}
	return cnt;
}

int main(){
	ios::sync_with_stdio(false);
	cin>>m>>a>>b;
	d[0]=0;
	for(int i=1;i<1111111;i++){
		d[i]=m+1;
	}
	ll g=gcd(a,b);
	ll i=g;
	ll cnt=1;
	while(i<=m){
		// cout<<i<<":"<<cnt<<endl;
		if(i-a>=0 && d[i-a]!=m+1){
			cnt+=fill(i,i);
			if(cnt-1==i/g){
				break;
			}
		}
		i+=g;
	}
	ll ans=0;
	ll j=0;
	for(;j<i;j+=g){
		ans+=(m-d[j]+1);
	}
	// cout<<"A"<<ans<<endl;
	ll mg=m/g*g;
	ans+=som(m-mg+1,m-i+1,g);
	cout<<ans<<endl;return 0;
	for(;j<i;j+=g){
		ans+=(m-d[j]+1);
	}
	// cout<<"i:"<<i<<endl;
	if(i>m){
		for(ll j=0;j<=m;j++){
			ans+=(m-d[j]+1);
		}
		cout<<ans<<endl;return 0;
	}
	for(ll j=0;j<i;j+=g){
		// cout<<d[j]<<endl;
		ans+=(m-d[j]+1)*g;
	}
	// cout<<ans<<"AAA"<<endl;
	ll mm = m/g*g;
	ans+=((mm-i)/g+2)*((mm-i)/g+1)/2*g-g;
	// cout<<ans<<"BBB"<<endl;
	ans += (m-mm+1)*(m-mm+2)/2;
	cout<<ans<<endl;
	return 0;
}

#include <iostream>

using namespace std;

typedef long long ll;

ll m, a, b, br[300005], prvi[300005];
bool bio[300005];
const ll MAXN = (ll)3e5;

ll gcd(ll x, ll y){
	if(!y)
		return x;
	return gcd(y, x % y);
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> m >> a >> b;
ll sad = 0, maxi = 0;
while(1){
	if(bio[sad])
		break;
	bio[sad] = 1;
	maxi = max(maxi, sad);
	prvi[sad] = maxi;
	if(sad < b){
		if(sad + a > m)
			break;
		sad += a;
	}
	else{
		sad -= b;
	}
}
ll sol = 0;
sad = 0;
for(int i = a ; i < MAXN ; ++i){
	bio[i] = bio[i - a];
	if(prvi[i] || !bio[i])
		continue;
	prvi[i] = max((ll)i, prvi[i - a]);
}
for(int i = 0 ; i < MAXN ; ++i){
	if(!bio[i])
		continue;
	br[prvi[i]]++;
}
for(int i = 0 ; i < min(m + 1, MAXN) ; ++i){
	sad += br[i];
	sol += sad;
}
if(m >= MAXN){
	int d = gcd(a, b);
	ll lst = MAXN - 1;
	for(int i = MAXN ; i <= m && i % d ; ++i){
		sol += sad;
		lst = i;
	}
	m = m - lst;
	ll kolko = m / d;
	sol += d * sad * kolko;
	sol += d * ((kolko * (kolko + 1)) / 2);
	sol += (m % d) * (sad + kolko + 1);
}
cout << sol << endl;

return 0;
}

//IOI 2021

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2 * 100 * 1000 + 17;

ll m, a, b, p[MAXN], x, g, y, ans;

void dfs(ll v = 0, ll mx = 0) {
	p[v] = mx;
	if (v - b > 0 && p[v - b] == min(m + 1, a + b))
		dfs(v - b, max(mx, v - b));
	if (v + a < min(a + b, m + 1) && p[v + a] == min(a + b, m + 1))
		dfs(v + a, max(v + a, mx));
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> m >> a >> b;
	fill(p, p + MAXN, min(m + 1, a + b));
	dfs();
	for (int i = 0; i < min(a + b, m + 1); i++)
		ans += min(m + 1, a + b) - p[i];
	g = __gcd(a, b);
	x = (a + b) / g + 1;
	y = m / g + 1;
	if (m >= (a + b))
		ans += g * (y * (y + 1) / 2 - (x - 1) * x / 2) - (g - 1 - (m % g)) * y;
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll m, a, b;
    cin >> m >> a >> b;
    vector<ll> v(a + b + 1, 1e9);
    v[0] = 0;
    ll Max = 0;
    ll cur = 0;
    while (true) {
        while (cur < b) {
            cur += a;
            Max = max(cur, Max);
            v[cur] = Max;
        }
        cur -= b;
        if (v[cur] != 1e9) {
            break;
        }
        v[cur] = Max;
    }
    ll d = __gcd(a, b);
    ll ans = 0;
    for (int i = 0; i <= (a + b) / d; ++i) {
        if (v[d * i] != 1e9)
            ans += max(1ll * 0, m - v[d * i] + 1);
        else ans += max(1ll * 0, m - i * d + 1);
    }
    if (m / d > (a + b) / d)
        ans += max(1ll * 0,
                   (m / d - (a + b) / d) * (m + 1) - d * (((a + b) / d + m / d + 1) * (m / d - (a + b) / d)) / 2);
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

int gcd(int x, int y){
	return y == 0 ? x : gcd(y, x % y);
}

int rec[N << 1], cnt[N << 1];

int main(){
	int m, a, b, now, tot, maxx, _gcd, rem;
	long long ans;
	cin >> m >> a >> b;
	_gcd = gcd(a, b);
	a /= _gcd;
	b /= _gcd;
	now = 0; tot = 1; maxx = 0;
	while (tot < a + b){
		if (now >= b) now -= b;
		else{
			now += a;
			maxx = max(maxx, now);
		}
		rec[now] = maxx;
		tot++;
	}
	for (int i = 0; i <= a + b - 1; i++) cnt[rec[i]]++;
	for (int i = 1; i <= a + b - 1; i++) cnt[i] += cnt[i - 1];
	ans = 0;
	rem = m % _gcd;
	m /= _gcd;
	if (m >= a + b - 1){
		for (int i = 0; i <= a + b - 2; i++) ans += cnt[i] * _gcd;
		ans -= (m + 1) * (_gcd - rem - 1);
		ans += 1LL * ((a + b) + m + 1) * (m - (a + b) + 2) / 2 * _gcd;
	}
	else{
		for (int i = 0; i <= m; i++) ans += cnt[i] * _gcd;
		ans -= cnt[m] * (_gcd - rem - 1);
	}
	cout << ans << '\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX=1e6+5;
ll MOD=1e9+7;
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fbo find_by_order
#define ook order_of_key
#define up upper_bound
#define lb lower_bound
#define pq priority_queue
#define pll pair<ll,ll>
using namespace __gnu_pbds;
#define boost               ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll add(ll a,ll b){return (a+b)%MOD;}
ll mul(ll a,ll b){return (a*b)%MOD;}
ll visited[MAX];
int main()
{
	boost;
	ll m,a,b,ans=0;
	cin>>m>>a>>b;
	ordered_set s;
	pq<ll,vector<ll>,greater<ll>>q;
	visited[0]=1;
	q.push(0);
	s.insert(0);
	for(ll i=0;i<=min(m,(ll)2e5);i++){
		while(q.size() && q.top()<=i){
			ll x=q.top();
			q.pop();
			if(!visited[max((ll)0,x-b)]){
				visited[x-b]=1;
				q.push(x-b);
				s.insert(x-b);
			}
			if(!visited[x+a]){
				visited[x+a]=1;
				q.push(x+a);
				s.insert(x+a);
			}
		}
		ans+=s.ook(i+1);
	}
	if(m<=2e5){
		cout<<ans;
		return 0;
	}
	ll x=__gcd(a,b);
	//debug(x);
	ll y=2e5+1;
	//debug2((y*(y+1))/2,ans);
	ll a1=m/x,b1=(y)/x;
	ll c=m%x,d=(y)%x;
	ans+=(((a1-b1+1)*(a1+b1))/2)*x;
	ans-=(b1+1)*d+(a1+1)*(x-c-1);
	cout<<ans+(a1-b1+1)*x;

}

#include <bits/stdc++.h>

using namespace std;

long long res;
long long m,a,b,lim;
bool vis[1000010];

void f(int u) {
    if(u < 0 or u > lim or vis[u]) return;
    vis[u] = 1;
    res++;
    f(u + a);
    f(u - b);
}

int main() {

    scanf("%lld %lld %lld", &m, &a, &b);

    res = 1;
    vis[0] = 1;

    long long rans = 0;
    long long cur = a + b - __gcd(a,b);

    for (int i = 0; i <= min(1LL * m, cur); ++i) {
        if(i - a >= 0 and vis[i - a]) {
            lim = i;
            f(i);
        }
        rans += res;
    }

    if(m <= cur) {
        printf("%lld\n", rans);
        return 0;
    }

    auto get = [] (long long x) {
        return x * (x + 1) / 2;
    };

    //cout << "lim: " << cur << " " << rans << "\n";
    //cout << m - cur << " test\n";
    rans += (get(m) - get(cur) + m - cur) / __gcd(a,b) + (get(m) - get(cur) + m - cur) % __gcd(a,b);

    printf("%lld\n", rans);

    return 0;
}

#include<bits/stdc++.h>

typedef long long ull;

const int N = 2e5;

ull m, a, b;
ull res;

int cnt, lim;

bool ok[N + 3];

int gcd(int a, int b) {return !b ? a : gcd(b, a % b); }

void dfs(int u) {
	if(ok[u]) return ;
	// printf("u = %d\n", u);
	ok[u] = 1, cnt++;
	if(u + a <= lim) dfs(u + a);
	if(u >= b) dfs(u - b);
}

ull getans(int x, int u) {
	ull res = 0;
	int top = x / u * u;
	res += 1ll * top / u * (top / u - 1) * u / 2;
	for(int i = top; i <= x; i++) res += i / u;
	return x + 1 + res;
}

int main() {
	scanf("%lld %lld %lld", &m, &a, &b);
	if(a == 1) printf("%lld\n", (m + 2) * (m + 1) / 2), exit(0);
	res = 1, ok[0] = 1, cnt = 1;
	for(lim = 1; lim <= a + b; lim++) {
		// if(lim % 50 == 0) printf("lim = %d\n", lim);
		if(lim >= a && ok[lim - a]) dfs(lim);
		res += cnt;
	}
	// puts("111");
	int u = gcd(a, b); res += getans(m, u) - getans(a + b, u);
	printf("%lld\n", res);
	return 0;
}

/*
void workba() {
	res = m + 1;
	int i = 0;
	while(i <= m - a) res += i, i += a;
	while(i <= m) res += i / a, i++;
	printf("%lld\n", res);
	exit(0);
}

void workab() {
	res = m + 1;
	int i = a - 1;
	while(i <= m) res += (i - a + 1) / b * a, i += a; i -= a - 1;
	while(i <= m) res += i / a * (a / b), i++;
	printf("%lld\n", res);
	exit(0);
}
*/

#include<bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define MN 300005
#define MM 600005
#define ll long long
int m,a,b,d;
int v[MN],que[MN],l,r,cnt;
int f[MN];
ll ans;
int main(){
	scanf("%d%d%d",&m,&a,&b),d=__gcd(a,b),a/=d,b/=d;
	f[0]=1,cnt=1,v[0]=1,l=1,r=0;
	F(i,1,a+b-1){
		if(i>=a&&v[i-a])v[i]=1,que[++r]=i,++cnt;
		while(l<=r){
			int u=que[l++];
			if(u+a<=i&&!v[u+a])v[u+a]=1,que[++r]=u+a,++cnt;
			if(u-b>=0&&!v[u-b])v[u-b]=1,que[++r]=u-b,++cnt;
		}f[i]=cnt;
	}
	if(m<(ll)(a+b)*d){
		F(i,0,a+b-1){
			if(m>=(ll)(i+1)*d)ans+=(ll)f[i]*d;
			else{ans+=(ll)f[i]*(m-(ll)i*d+1);break;}
		}
		printf("%lld\n",ans);
	}
	else{
		F(i,0,a+b-1)ans+=(ll)f[i]*d;
		ll x=m/d;
		ans+=(ll)(a+b+1+x)*(x-a-b)/2;
		ans+=(ll)(m-x*d+1)*(x+1);
		printf("%lld\n",ans);
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long n;
long long a,b,sum;
long long c[200007];
long long d[200007];
int vis[200007];
priority_queue<pair<long long,long long> >pq;
int main(){
    scanf("%lld%lld%lld",&n,&a,&b);
    sum=a+b;
    long long gcd=__gcd(a,b);
    long long ans=0;
    if(n>sum){
        long long tmp=n/gcd;
        ans=gcd*(sum/gcd+tmp+1)*(tmp-sum/gcd)/2;
        for(long long i=tmp*gcd;i<=n;++i)
            ans+=tmp+1;
    }
    memset(c,0x3f3f3f3f,sizeof(c));
    pq.push(make_pair(0,0));
    c[0]=0;
    while(!pq.empty()){
        long long x=pq.top().second;
        pq.pop();
        if(vis[x])
            continue;
        else
            vis[x]=1;
        if(x+a<sum){
            if(c[x+a]>max(c[x],x+a)){
                c[x+a]=max(c[x],x+a);
                pq.push({-c[x+a],x+a});
            }
        }
        if(x>=b){
            if(c[x-b]>c[x]){
                c[x-b]=c[x];
                pq.push({-c[x-b],x-b});
            }
        }
    }
    for(int i=0;i<sum&&i<=n;++i)
        if(c[i]<sum)
            d[c[i]]++;
    for(int i=0;i<sum&&i<=n;++i){
        d[i]+=d[i-1];
        ans+=d[i];
    }
    printf("%lld",ans);
    return 0;
}

#include    <bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define __unique(V) (V).resize(unique((V).begin(),(V).end())-(V).begin())
#define cntbit(X)   __builtin_popcount((X))
#define bit(S,i) (((S)>>(i))&1)
#define PI	acos(-1)
#define fi  first
#define se  second
#define LL  long long
#define ii  pair<int,int>
#define iii pair<int,ii>
#define eb  emplace_back
#define TASK "1146D"
using namespace std;
const int maxn = 2e6;
const int maxa = 1e5 + 5;
int m,a,b;
int M[maxn],L[maxn];
bool ok[maxn];
///--------------------------
void    readf(){
    cin >> m >> a >> b;
}
///--------------------------
LL sum(int k){
    int T = k / a;
    int D = k % a;
    return (1LL * (D + 1) * T + ((1LL * a * T * (T - 1))>>1LL));
}
///--------------------------
LL  get(int u,int v){
    return (sum(v) - sum(u - 1));
}
///--------------------------
void    solve(){
    queue <int> qu;
    M[0] = 0; ok[0] = 1;
    qu.push(0);
    while (qu.size()){
        int u = qu.front(); qu.pop();
        for(auto v : {u - b, u + a}) if (0 <= v && v <= maxn && !ok[v]){
            M[v] = max(v,M[u]); ok[v] = 1;
            qu.push(v);
        }
    }
    for(int i = maxn; i >= 0; --i) if (ok[i]) L[i % a] = i;
    for(int i = 0; i < maxn; ++i) M[i % a] = min(M[i % a],M[i]);
    LL ans = 0;
    for(int i = 0; i < a; ++i) if (i == 0 || (i > 0 && L[i] > 0))
    if (M[i] <= m)
        ans += (get(M[i] + a - i,m + a - i) - 1LL * (m - M[i] + 1) * ((L[i] + a - i - 1)/a));
    cout << ans << '\n';
}
///--------------------------
int     main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    #ifdef TLH2203
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    #endif // TLH2203
    readf();
    solve();
}

#include<bits/stdc++.h>
using namespace std;

long long id[300010];
long long f[300010];

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	long long m, a, b;
  	cin >> m >> a >> b;
  	long long h=0;
  	long long maxi=0;
  	f[0]=1;
  	int contador=0;
  	long long d=__gcd(a,b);
  	long long ms=m, as=a, bs=b;
  	m/=d, a/=d, b/=d;

  	for( ; contador<b; ){
  		h+=a;
  		if(h>maxi) maxi=h;
  		if(id[h]==0){
			id[h]=maxi;
			f[maxi]++;
			if(h<b) contador++;
		}
  		h%=b;
  		if(id[h]==0){
			id[h]=maxi;
			f[maxi]++;
			if(h<b) contador++;
		}
	}
	for(int i=1; i<=a+b-2; i++){
		if(id[i]==0){
			id[i]=id[i-b];
			f[id[i]]++;
		}
	}
	long long sumf=1;
	for(int i=1; i<=min(m,a+b-2); i++){
		f[i]+=f[i-1];
		sumf+=f[i];
	}
	if(m>=a+b-1){
		sumf+=((m+2)*(m+1)/2)-((a+b)*(a+b-1)/2);
	}
	sumf*=d;
	ms%=d;
	if(m>=a+b-1) sumf+=(m+1)*ms;
	else sumf+=f[m]*ms;
	printf("%lld\n", sumf);
}

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <set>

using namespace std;

void cre(vector<vector<int> > &vv, int n, int idx, vector<int> v, int m){
    if(m==0){
        vv.push_back(v);
        return;
    }
    if(idx == n) {
        if(m==0)vv.push_back(v);
        return;
    }
    v[idx] = 1;
    cre(vv,n,idx+1,v,m-1);
    v[idx] = 0;
    cre(vv,n,idx+1,v,m);
}

int bsearch(vector<int> &v, int l, int r, int val){
    if( l >= r) return l;
    int mid = (l+r)/2;
    if(v[mid] == val) return mid;
    if(v[mid] < val){
        if(v[mid+1] > val) return mid;

        return bsearch(v,mid+1,r,val);
    }
    return bsearch(v,l,mid,val);
}

int bsearch2(vector<int> &v, int l, int r, int val){
    if(l>=r) return r;
    int mid = (l+r)/2;
    if(v[mid] == val) return mid;
    if(v[mid] < val){
        if(v[mid+1] >= val) return mid+1;
        return bsearch2(v,mid+2,r,val);
    }
    return bsearch2(v,l,mid,val);
}

void crefac(vector<vector<int> > &vv, int n, int idx, vector<int> v,set<int> s){
    if(idx==n){
        vv.push_back(v);
        return;
    }
    for(auto it = s.begin() ; it!=s.end() ; it++){
        int x = *it;
        // cout << x << endl;
        v[idx] = x;
        set<int> xx = s;
        xx.erase(x);
        crefac(vv,n,idx+1,v,xx);
        // s.insert(x);
    }
}

long long gcd(long long a, long long b){
    if (a%b==0) return b;
    return gcd(b,a%b);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long m,a,b;
    cin >> m >> a >> b;
    long long ans = a;
    long long k = 1;
    long long now = a;
    long long old = a/b+1;
    if(a%b != 0) old+=1;
    if(m < a){
        cout << m+1;
        return 0;
    }
    long long d= gcd(a,b);
    while(k<b/d){
        long long next = (k*a)%b + a;
        if(next > m){

            ans += old*(m-now+1);
            cout << ans;
            return 0;
        }
        ans += old*(next-now);
        // cout << next << " " << now << " " << next-now << endl;
        k++;
        old += next/b;
        if(next%b != 0) old += 1;
        // cout << "old = " << old << endl;
        while((k*a)%b+a < next && k < b/d){
            old += ((k*a)%b+a)/b+1;
            if(((k*a)%b+a) %b != 0) old+=1;
            // cout << "old = " << old << endl;

            k++;
        }
        // old += 0;
        now = next;
        // cout << "ans = " << ans << endl;
    }
    // now = a+b;
    ans += (m-now+1)*(now/d+m/d+2)/2;
    // ans -= m/d - (now-1)/d;

    cout << ans << endl;

    return 0;
}

/*---------------Go Code GO---------------*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using Order_Set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define     PI              acos(-1.0)
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     precision(a)    fixed<<setprecision(a)
#define     endl            '\n'
#define     Flush           cout<<flush
#define     LLMX            0x3fffffffffffffff

long long M,A,B;
long long Ans[3000005];

int main()
{
    long long i,j,k,l,tst=0,ans=0, csno=0, pointer=0;
    cin>>M>>A>>B;
    Ans[0]=1;
    pointer = A;
    for(i=1; i<(A+B); i++)
    {
        while(pointer<=i)
        {
            Ans[i]++;
            while(pointer-B>0)
            {
                pointer-=B;
                Ans[i]++;
            }
            pointer+=A;
        }
        Ans[i]+=Ans[i-1];
        //cout<<Ans[i]<<' '<<endl;
    }
    for(i=1; i<(A+B); i++) Ans[i]+=Ans[i-1];
    if(M<A+B)
    {
        cout<<Ans[M]<<endl;
        return 0;
    }
    long long multp , last_n, first_n, extra, nmbrMultp, total;

    multp = __gcd(A,B);
    first_n = (A + B)/multp;

    last_n = (M/multp);

    total = multp*((last_n+1)*(last_n)-(first_n-1)*first_n)/2;
    total+= last_n*(M%multp)+Ans[A+B-1]+M+1-(A+B);
    cout<<total<<endl;

//    total = multp*(nmbrMultp*firstMultp+multp*(((nmbrMultp-1)*nmbrMultp)/2))+nmbrMultp;
//    total+=lastMultp*(M-lastMultp+1)+Ans[A+B-1]+1;

    cout<<total<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int cur, m, a, b;
bool vis[200005];
int dis;
void dfs(int x) {
	if (x > cur) return;
	if (x < 0) return;
	if (vis[x]) return;
	vis[x] = true;
	++dis;
	dfs(x + a);
	dfs(x - b);
}
int main() {
	scanf("%d%d%d", &m, &a, &b);
	vis[0] = true;
	dis = 1;
	ll ans = 1;
	for (int i = 1; i <= min(m, a + b); ++i) {
		cur = i;
		if (i >= a && vis[i - a]) {
			dfs(i);
		}
		ans += dis;
	}
	if (m > a + b) {
		ans += (ll)(a + b + 2 + m + 1) * (m - a - b) / 2;
	}
	printf("%lld\n", ans);
}

 #include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200005;
int m,a,b,vis[N],x=1;
long long ans=1;
int rd()
{
    char c=getchar();int s=0,f=1;
    while(c>'9'||c<'0'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9') s=s*10+c-'0',c=getchar();
    return s*f;
}
ll dfs(ll u,ll r)
{
    if(vis[u]) return 0;
    ll res=1;vis[u]=1;x++;
    if(u+a<=r) dfs(u+a,r);
    if(u-b>=0) dfs(u-b,r);
    return res;
}
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    // freopen("ddjxd.in","r",stdin);
    // freopen("ddjxd.out","w",stdout);
    m=rd();a=rd();b=rd();
    ans=min(m+1,a);vis[0]=1;
    for(int i=a;i<=min(a+b,m);i++)
    {
        if(i-a>=0&&vis[i-a]) dfs(i,i);
        ans+=x;
    }
    int p=gcd(a,b);
    if(a+b<m) for(int i=0;i<p;i++)
    {
        int x=(m-i)/p+1,y=(a+b+i)/p+1;
        ans+=1ll*(x-y)*(x+y+1)/2;
    }
    printf("%lld\n",ans);
    return 0;
}

/**
Monday left me broken
Tuesday I was through with hoping
Wednesday my empty arms were open
Thursday waiting for love, waiting for love
Thank the stars it's Friday
I'm burning like a fire gone wild on Saturday
Guess I won't be coming to church on Sunday
I'll be waiting for love, waiting for love
To come around
**/

#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
typedef pair <long long ,long long>	PII;
typedef priority_queue<PII,vector<PII>,greater<PII>> pairMinHeap;
typedef priority_queue<PII> pairMaxHeap;
typedef priority_queue<long long ,vector<long long>,greater<long long>> minHeap;
typedef priority_queue<long long> maxHeap;

#define what_is(x) cerr <<#x<<" is "<<x<<endl;
#define wis(x,y) cerr <<#x<<" is "<<x<<" and "<<#y<<" is "<<y<<endl;

#define INF 1e9
const int N=3e5+33;
const long long MD=1000000007;

inline long long mul(long long a, long long b){
    return (a*b)%MD;
}

inline long long po(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1)ans = mul(ans,a);
        a = mul(a,a);
        b/=2;
    }
    return ans;
}

long long n,m,t,k;
long long arr[N];

long long a,b,ans;

int mark[N];

int main(){
    ios::sync_with_stdio(false);
    cin>>m>>a>>b;

    long long d = __gcd(a,b);

    for(int i=0;i<N;i++)mark[i]=INF;

    pairMinHeap bfs;
    bfs.push({0,0});

    while(!bfs.empty()){
        auto x=bfs.top();
        bfs.pop();

        if(mark[x.s] == INF){
            mark[x.s]=x.f;
            if(x.s+a <= min(a+b-d,m) && mark[x.s+a]==INF)bfs.push({x.f,x.s+a});
            if(x.s-b > 0 && mark[x.s-b]==INF)bfs.push({max(x.f,x.s),x.s-b});
        }
    }

    for(int i=0;i<= a+b-d && i<=m;i++){
        //wis(i,mark[i])
        if(mark[i]!=INF && max(i,mark[i])<=m){
            //  wis(i,(m-max(i,mark[i])+1))
            ans+= (m-max(i,mark[i])+1);
        }
    }

    if(m<=a+b-d){
        cout<<ans;
        return 0;
    }

    long long n = (m-(a+b-d))/d;
    ans += n + (n*(n-1)/2*d);

    ans += (m-n-(a+b-d))*(n*d);

    cout<<ans;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define vi vector<int>
#define pb push_back
#define ll long long
#define _t(a) __typeof(a.end())
#define fi first
#define se second
#define gcd __gcd

int m, a, b, ta[1000005], g;
ll ans, n, far;

void printa(){
    while(far != m && far%g != 0)
        ans += far/g +1, far++;
    while(far != m && m%g != 0)
        ans += m/g +1, m--;
    ans += m/g +1;
    m--;
    cout<< ans +g*(m/g -far/g +1)*(far/g +m/g +2)/2 << "\n";
}

bool con = 1;
void dfs(int p){
    if(ta[p] == -1) n++;
    if(ta[p] == 1) return;
    if(p && n == far/g +1){
        printa();
        con = 0;
        return;
    }
    if(p -b > 0 && ta[p] < 0){
        ta[p] = 0;
        dfs(p -b);
        if(!con) return;
    }
    if(p +a <= m){
        if(p +a > far){
            ans += (p +a -far)*n;
            far = p +a;
        }
        ta[p] = 1;
        dfs(p +a);
    }else cout<< ans +(m -far +1)*n << "\n";
}

int solve(){
    memset(ta, -1, sizeof ta);
    cin >> m >> a >> b;
    ans = n = far = 0;
    g = gcd(a, b);
    dfs(0);
    return 0;
}

int main(){
    int TC = 1;
    //cin >> TC;
    while(TC--) solve();
    return 0;
}

#include <algorithm>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int gcd(int a, int b)
{
	while(a != b)
    {
        if(a > b)
            a -= b;
        else
            b -= a;
    }

    cout << "HCF = " << a;
    return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m, a, b;
  cin >> m >> a >> b;
  vector<int> first(a + b, -1);
  int x = 0;
  int y = 0;
  while (true) {
    first[x] = y;
    if (x >= b) {
      x -= b;
    } else {
      x += a;
    }
    if (x == 0) {
      break;
    }
    y = max(y, x);
  }
  long long ans = 0;
  for (int i = 0; i < a + b; i++) {
    if (first[i] != -1) {
      ans += max(0, m - first[i] + 1);
    }
  }
  if (m >= a + b) {
    int left = m - (a + b);
    int g = gcd(a, b);
    int u = left / g * g;
    long long first = left - 0 + 1;
    long long last = left - u + 1;
    long long cnt = (first - last) / g + 1;
    ans += (first + last) * cnt / 2;
  }
  cout << ans << '\n';
  return 0;
}

#include <bits/stdc++.h>

#define ll long long

using namespace std;
ll m, a, b;

void dfs(ll n, vector<bool> &can, ll &ans, ll limit) {
    ans++;
    can[n] = true;
    if (n - b >= 0 && !can[n - b]) {
        dfs(n - b, can, ans, limit);
    }
    if (n + a <= limit && !can[n + a]) {
        dfs(n + a, can, ans, limit);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> m >> a >> b;
    if (a + b < m) {
        ll d = __gcd(a, b);
        ll k = m / d;
        cout << (k + 1) * (m + 1) - d * ((k * (k + 1)) / 2);
    } else {
        vector<ll> dp(m + 1);
        dp[0] = 1;
        vector<bool> used(m + 1);
        used[0] = true;
        for (int i = 1; i <= m; ++i) {
            ll ans = 0;
            if (i - a >= 0 && used[i - a]) {
                dfs(i, used, ans, i);
            }
            dp[i] = dp[i - 1] + ans;
        }
        ll result = 0;
        for (int i = 0; i <= m; ++i)
            result += dp[i];
        cout << result;
    }
    return 0;
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
string toString(long long x)
{
stringstream ss;
ss << x;
string str = ss.str();
return str;
}
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
long long n,a,b;
bitset<30005> visited;
int BFS(int starting,int maxe)
{
    if(starting > maxe || starting < 0||  visited[starting])
        return 0;
    visited[starting] = true;
    return 1 + BFS(starting + a,maxe) + BFS(starting - b,maxe);
}
long long sumR(long long r)
{
    return r * (r + 1) / 2;
}
int main()
{
    IO;
    cin >> n >> a >> b;
    long long f1 = 0;
    long long c = 0;
    for(int i = 0;i < 30000 && c <= n;i++,c++)
    {
        visited.reset();
        f1 += BFS(0,i);
       // cout << i << endl;
    }
    int len = n - c + 1;
    long long s2 = sumR(n) - sumR(n - len) + 1LL*len;
    s2 /= __gcd(a,b);
    cout << f1 + s2;
    return 0;
}

#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 2e7;
int f[maxn];
bool vis[maxn];
signed main() {
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(10);
  int m, a, b;
  cin >> m >> a >> b;
  int d = __gcd(a, b);
  int p = 0, mx = a;
  f[0] = 1;
  int cnt = 1;
  vis[0] = 1;
  while(cnt <= mx / d) {
    if(p - b < 0) {
      p += a;
      mx = max(mx, p);
      if(!vis[p]) {
        vis[p] = 1;
        ++cnt;
        f[mx] = cnt;
      }
    } else {
      p -= b;
      if(!vis[p]) {
        vis[p] = 1;
        ++cnt;
        f[mx] = cnt;
      }
    }
  }
  for(int i = 1; i < mx; ++i) {
    f[i] = max(f[i], f[i - 1]);
  }
  long long res = 0;
  for(int i = 0; i <= min(m, mx); ++i) {
    res += f[i];
    // cout << i << ' ' << f[i] << endl;
  }
  if(m - mx < 5 * d) {
    for(int i = mx + 1; i <= m; ++i) {
      res += i / d + 1;
    }
    cout << res << endl;
    return 0;
  }
  int cur = mx + 1;
  while(cur % d != 0) {
    res += cur / d + 1;
    ++cur;
  }
  while(m % d != 0) {
    res += cur / d + 1;
    --m;
  }
  res += m / d + 1;
  --m;
  // cout << cur << ' ' << m << endl;
  // cout << res << endl;
  res += 1ll * (m / d + cur / d + 2) * (m / d - cur / d + 1) * d / 2;
  cout << res << endl;
  return 0;
}

#include<bits/stdc++.h>
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d ",x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define pf2(x,y) printf("%d %d ",x,y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define pf3(x,y,z) printf("%d %d %d ",x,y,z)
#define sfc(c) scanf(" %c",&c)
#define pfc(c) printf("%c",c)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define INF 1000000008
#define LLINF ll(1e18+10)
#define ENDL puts("")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef unsigned int uint;
typedef long double ld;

template<class T>
void printVector(T begin, T end)
{
    for(auto i=begin; i!=end; i++)
    {
        cout<<*i<<' ';
    }
    cout<<endl;
}

ll readLL() {
    ll x;
    cin >> x;
    return x;
}

int readInt() {
    int x;
    cin >> x;
    return x;
}

int gcd(int a, int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}

bool u[500300];
ll cnt=1;
ll res=0;
int m,a,b;

void dfs(int v, int l, int r)
{
    u[v]=1;
    cnt++;
    if(v+a<=r)
    {
        if(!u[v+a])
        {
            dfs(v+a,l,r);
        }
    }
    if(v-b>=0)
    {
        if(!u[v-b])
        {
            dfs(v-b,l,r);
        }
    }
}

int main()
{
    /*
    freopen("caravan.in","r",stdin);
    freopen("caravan.out","w",stdout);
    /**/

    u[0]=1;

    sf3(m,a,b);
    int g=gcd(a,b);
    int i=0;
    for(i=0; i<=min(m,300000); i++)
    {
        if(i-a>=0&&u[i-a])
        {
            dfs(i,0,i);
        }
        res+=cnt;
    }
    while(i<=m&&i%g!=0)
    {
        if(i-a>=0&&u[i-a])
        {
            dfs(i,0,i);
        }
        res+=cnt;
        i++;
    }
    ll tmp=(m-i)/g+1;
    res+=(ll)cnt*tmp+tmp*(tmp+1)/2;
    cout<<res;

    return 0;

}

#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=5e5+5;
ll m, a, b;
ll A[N];

ll f(ll b){
  if(b<0)return 0;
  return b*(b+1LL)/2LL;
}
ll f(ll a, ll b){
  return f(b)-f(a-1);
}

bool valid(ll c){
  return c>=0 && c<a+b+5;
}
typedef pair<ll,ll> ii;
ll cnt[N];

int main(){FIN;
  cin >> m >> a >> b;
  fill(A,A+a+b+5,1LL<<60);
  priority_queue<ii,vector<ii>,greater<ii> > pq;
  pq.push({0,0});A[0]=0;
  while(!pq.empty()){
    ll d=pq.top().fst, u=pq.top().snd;pq.pop();
    if(d>A[u])continue;
    ll c=u+a;
    if(valid(c)&&A[c]>max(c,d))A[c]=max(c,d),pq.push({A[c],c});
    c=u-b;
    if(valid(c)&&A[c]>max(c,d))A[c]=max(c,d),pq.push({A[c],c});
  }
  fore(x,0,min(a+b+5,m+1))if(valid(A[x])){
    cnt[A[x]]++;
  }
  ll ans = 0, cur = 0;
  fore(x,0,min(a+b+5,m+1)){
    cur += cnt[x];
    ans += cur;
  }
  if(m>=a+b+5) ans += f(a+b+6,m+1);
  cout << ans << "\n";
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<ll,ll>get_coeff(ll p,ll q)
{
    if(q==0)
        return make_pair(1,0);
    auto w=get_coeff(q,p%q);
    return make_pair(w.second,w.first - (p/q)*w.second);
}
void solve()
{
    ll a,b,m;
    cin>>m>>a>>b;
    if(m<a)
    {
        cout<<m+1;
        return ;
    }
    ll hcf=__gcd(a,b),a1=(a/hcf),b1=(b/hcf);
    auto v=get_coeff(a,b);
    ll x=v.first,y=v.second;
    ll req=x%b1;
    if(req<0)
        req+=b1;
    ll times=(x-req)/b1;y=y+times*a1;x=req;
    ll ans=0;
    if(m>=a+b)
    {
        ll upper=(m-hcf)/hcf,lower=a1+b1;
        ans+=(m-a-b+1)*(a1+b1);
        ans+=(m+1)*(upper-lower+1) - hcf*((upper*upper + upper)/2 - (lower*lower - lower)/2);
        ans+=m%hcf + 1;
        m=a+b-1;
    }
    vector<ll>max_pos(a1+b1+3);
    for(int i=1;i<=a1+b1;++i)
        max_pos[i]=max(max_pos[i-1],max_pos[i-1]%b + a);
    for(ll i=0;i<a1;++i)
    {
        ll x2=x*i,y2=y*i;
        req=x2%b1;
        if(req<0)
            req+=b1;
        times=(x2-req)/b1;y2=y2+times*a1;x2=req;
        if(y2>0)
        {
            req=y2%a1 - a1;
            times=(y2-req)/a1;
            x2+=times*b1;
            y2=req;
        }
        ll pos=max_pos[x2];
        //cout<<pos<<" "<<x2<<" "<<y2<<"\n";
        for(ll j=i*hcf;j<=m;j+=a)
            ans+=max(m-max(pos,j)+1,(ll)0);
    }
    cout<<ans;
}
int main()
{
    int t=1;
    while(t--)
        solve();
}

#include <iostream>

using namespace std;

typedef long long ll;

ll m, a, b, br[300005];
bool bio[300005];
const int MAXN = (int)2e5;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> m >> a >> b;
ll sad = 0, maxi = 0;
while(1){
	if(bio[sad])
		break;
	bio[sad] = 1;
	maxi = max(maxi, sad);
	br[maxi]++;
	if(sad < b){
		if(sad + a > m)
			break;
		sad += a;
	}
	else{
		sad -= b;
	}
}
ll sol = 0;
sad = 0;
for(int i = a ; i < 2 * a ; ++i){
	br[i + a] = bio[i];
}
for(int i = 0 ; i < min(m + 1, 3 * a) ; ++i){
	sad += br[i];
	sol += sad;
}
if(m >= 3 * a){
	ll svaki = 0, cur = 0;
	for(int i = 0 ; i < a ; ++i){
		cur += bio[i];
		svaki += cur;
	}
	ll kolko = (m - 3 * a) / a;
	sol += sad * kolko;
	sol += svaki * (((kolko) * (kolko + 1)) / 2);
	sad += kolko * svaki;
	for(int i = 0 ; i <= m % a ; ++i){
		sad += bio[i];
		sol += sad;
	}
}
cout << sol << endl;

return 0;
}

#include <bits/stdc++.h>

#define N 10000010

using namespace std;

typedef long long ll;

int head[N], to[N << 1], nxt[N << 1], tot, dis[N];

inline void add(int x, int y) {
	// cout << x << ' ' << y << endl ;
	to[ ++ tot] = y;
	nxt[tot] = head[x];
	head[x] = tot;
}

bool vis[N];

int ans = 0;

void dfs(int p) {
	if (!vis[p]) {
		vis[p] = true;
		// printf("QQQQQQQ %d\n", p);
		ans ++ ;
	}
	for (int i = head[p]; i; i = nxt[i]) {
		if (!vis[to[i]]) {
			dfs(to[i]);
		}
	}
}

int main() {
	// setIO("b");
	int x, a, b;
	cin >> x >> a >> b ;
	if (x >= a + b) {
		int d = __gcd(a, b);
		cout << (ll)d * (x / d) * (x / d + 1) / 2 + x / d + 1 << endl ;
		return 0;
	}
	vis[0] = 1, ans = 1;
	ll ans2 = 1;
	for (int i = 1; i <= x; i ++ ) {
		int pre, aft;
		pre = i - a;
		aft = i - b;
		if (pre >= 0) {
			add(pre, i);
		}
		if (aft >= 0) {
			add(i, aft);
		}
		if (pre >= 0 && vis[pre]) {
			dfs(pre), dfs(i);
		}
		// if (pre >= 0) {
		// 	if (aft >= 0) {
		// 		add(pre, i), add(i, aft);
		// 		if (vis[pre]) {
		// 			dfs(pre), dfs(i);
		// 		}
		// 	}
		// }
		// printf("Fuck %d : %d\n", i, ans);
		ans2 += ans;
	}
    // puts("Fuck");
	cout << ans2 << endl ;
	// fclose(stdin), fclose(stdout);
	return 0;
}

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

// #undef DEBUG
// #define DEBUG
// DEBUG {{{
#include <array>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>
template < int n, class... T >
typename std::enable_if< (n >= sizeof...(T)) >::type __output_tuple(
    std::ostream &, std::tuple< T... > const &) {}
template < int n, class... T >
typename std::enable_if< (n < sizeof...(T)) >::type __output_tuple(
    std::ostream &os, std::tuple< T... > const &t) {
  os << (n == 0 ? "" : ", ") << std::get< n >(t);
  __output_tuple< n + 1 >(os, t);
}
template < class... T >
std::ostream &operator<<(std::ostream &os, std::tuple< T... > const &t) {
  os << "(";
  __output_tuple< 0 >(os, t);
  os << ")";
  return os;
}
template < class T, class U >
std::ostream &operator<<(std::ostream &os, std::pair< T, U > const &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template < class T >
std::ostream &operator<<(std::ostream &os, const std::stack< T > &a) {
  os << "{";
  for(auto tmp = a; tmp.size(); tmp.pop())
    os << (a.size() == tmp.size() ? "" : ", ") << tmp.top();
  os << "}";
  return os;
}
template < class T, class Container, class Compare >
std::ostream &operator<<(std::ostream &os,
    std::priority_queue< T, Container, Compare > a) {
  os << "{ (top) ";
  while(a.size()) os << a.top() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
template < class T, class Container >
std::ostream &operator<<(std::ostream &os, std::queue< T, Container > a) {
  os << "{ ";
  while(a.size()) os << a.front() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
#ifdef DEBUG
#if !defined(DEBUG_OUT)
// #define DEBUG_OUT std::cerr
#endif
#define dump(...)                                                                \
  [&]() {                                                                        \
    auto __debug_tap = std::make_tuple(__VA_ARGS__);                             \
    DEBUG_OUT << "[" << __LINE__ << "] " << #__VA_ARGS__ << " = " << __debug_tap \
    << std::endl;                                                      \
  }()
template < class T >
inline void dump2D(T &d, size_t sizey, size_t sizex) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << "\t";
    for(size_t j = 0; j < sizex; j++)
      DEBUG_OUT << d[i][j] << (j + 1 == sizex ? "" : "\t");
    DEBUG_OUT << std::endl;
  }
}
template < class T >
inline void dump1D(T &d, size_t sizey) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << d[i] << (i + 1 == sizey ? "" : " ");
  }
  DEBUG_OUT << std::endl;
}
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        os << "{";
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : ", ") << *ite;
        os << "}";
        return os;
      }
#else
#define dump(...) (42)
#define dump2D(...) (42)
#define dump1D(...) (42)
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : " ") << *ite;
        return os;
      }
#endif
// }}}

/// --- math {{{ ///
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d;
  return b == 0 ? (x = a < 0 ? -1 : 1, y = 0, a < 0 ? -a : a)
    : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
}
ll modinv(ll a, ll mod) {
  ll x, y;
  extgcd(a, mod, x, y);
  if(x < 0) x += mod;
  return x;
}
ll modpow(ll a, ll b, ll mod) {
  ll r = 1;
  a %= mod;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
/// }}}--- ///

// LazySegmentTree( size [, initial] )
// LazySegmentTree( <data> )
/// --- LazySegmentTree {{{ ///
#include <cassert>
#include <initializer_list>
#include <iostream>
#include <vector>
template < class M_act >
struct LazySegmentTree {
public:
  using Monoid = typename M_act::Monoid;
  using X = typename Monoid::T;
  using M = typename M_act::M;

private:
  size_t n;
  int h;
  vector< X > data;
  vector< M > lazy;
  vector< size_t > nodeLength;
  // call before use data[i]
  void eval(size_t i) {
    if(lazy[i] == M_act::identity()) return;
    data[i] = M_act::actInto(lazy[i], nodeLength[i], data[i]);
    if(i < n) {
      lazy[i * 2] = M_act::op(lazy[i], lazy[i * 2]);
      lazy[i * 2 + 1] = M_act::op(lazy[i], lazy[i * 2 + 1]);
    }
    lazy[i] = M_act::identity();
  }
  // call before use seg[i] = data[i + n]
  void evalDown(size_t i) {
    i += n;
    for(int j = h - 1; j >= 0; j--) eval(i >> j);
  }
  // call after touch seg[i] = data[i + n]
  void propUp(size_t i) {
    i += n;
    while(i >>= 1)
      eval(i * 2), eval(i * 2 + 1), data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
  }

public:
  LazySegmentTree() : n(0) {}
  LazySegmentTree(size_t n, X initial = Monoid::identity()) : n(n) {
    if(n > 0) {
      h = 1;
      while(1u << h < n) h++;
      data.resize(2 * n, initial);
      lazy.resize(2 * n, M_act::identity());
      nodeLength.resize(2 * n, 1);
      for(size_t i = n - 1; i > 0; i--) // fill from deep
        data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]),
          nodeLength[i] = nodeLength[i * 2] + nodeLength[i * 2 + 1];
    }
  }
  template < class InputIter, class = typename iterator_traits< InputIter >::value_type >
    LazySegmentTree(InputIter first, InputIter last)
    : LazySegmentTree(distance(first, last)) {
      if(n > 0) {
        copy(first, last, begin(data) + n);
        for(size_t i = n - 1; i > 0; i--) // fill from deep
          data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
      }
    }
  LazySegmentTree(vector< X > v) : LazySegmentTree(v.begin(), v.end()) {}
  LazySegmentTree(initializer_list< X > v) : LazySegmentTree(v.begin(), v.end()) {}
  void act(int l, int r, const M &m) {
    if(l < 0) l = 0;
    if(l >= r) return;
    if(r > (int) n) r = n;
    evalDown(l);
    evalDown(r - 1);
    int tl = l, tr = r;
    for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) eval(l), lazy[l] = m, eval(l), l++;
      if(r & 1) --r, eval(r), lazy[r] = m, eval(r);
    }
    propUp(tl);
    propUp(tr - 1);
  }
  void set(size_t i, const X &x) {
    assert(i < n);
    evalDown(i);
    data[i + n] = x;
    propUp(i);
  }
  X get(size_t i) {
    assert(i < n);
    evalDown(i);
    return data[i + n];
  }
  X fold(int l, int r) {
    if(l < 0) l = 0;
    if(l >= r) return Monoid::identity();
    if(r > (int) n) r = n;
    evalDown(l);
    evalDown(r - 1);
    X tmpL = Monoid::identity(), tmpR = Monoid::identity();
    for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) eval(l), tmpL = Monoid::op(tmpL, data[l]), l++;
      if(r & 1) --r, eval(r), tmpR = Monoid::op(data[r], tmpR);
    }
    return Monoid::op(tmpL, tmpR);
  }
  int size() { return n; }
  inline void dum(int r = -1) {
#ifdef DEBUG
    if(r < 0) r = n;
    DEBUG_OUT << "{";
    for(int i = 0; i < min(r, (int) n); i++) DEBUG_OUT << (i ? ", " : "") << get(i);
    DEBUG_OUT << "}" << endl;
#endif
  }
};

/// }}}--- ///

/// --- Monoid examples {{{ ///
constexpr long long inf_monoid = 1e18 + 100;
#include <algorithm>
struct Nothing {
  using T = char;
  using Monoid = Nothing;
  using M = T;
  static constexpr T op(const T &, const T &) { return T(); }
  static constexpr T identity() { return T(); }
  template < class X >
    static constexpr X actInto(const M &, long long, const X &x) {
      return x;
    }
};

template < class U = long long >
struct RangeMin {
  using T = U;
  static T op(const T &a, const T &b) { return std::min< T >(a, b); }
  static constexpr T identity() { return T(inf_monoid); }
};

template < class U = long long >
struct RangeMax {
  using T = U;
  static T op(const T &a, const T &b) { return std::max< T >(a, b); }
  static constexpr T identity() { return T(-inf_monoid); }
};

template < class U = long long >
struct RangeSum {
  using T = U;
  static T op(const T &a, const T &b) { return a + b; }
  static constexpr T identity() { return T(0); }
};

template < class U >
struct RangeProd {
  using T = U;
  static T op(const T &a, const T &b) { return a * b; }
  static constexpr T identity() { return T(1); }
};

template < class U = long long >
struct RangeOr {
  using T = U;
  static T op(const T &a, const T &b) { return a | b; }
  static constexpr T identity() { return T(0); }
};

#include <bitset>

template < class U = long long >
struct RangeAnd {
  using T = U;
  static T op(const T &a, const T &b) { return a & b; }
  static constexpr T identity() { return T(-1); }
};

template < size_t N >
struct RangeAnd< std::bitset< N > > {
  using T = std::bitset< N >;
  static T op(const T &a, const T &b) { return a & b; }
  static constexpr T identity() { return std::bitset< N >().set(); }
};

/// }}}--- ///

/// --- M_act examples {{{ ///
template < class U = long long, class V = U >
struct RangeMinAdd {
  using X = U;
  using M = V;
  using Monoid = RangeMin< U >;
  static M op(const M &a, const M &b) { return a + b; }
  static constexpr M identity() { return 0; }
  static X actInto(const M &m, long long, const X &x) { return m + x; }
};

template < class U = long long, class V = U >
struct RangeMaxAdd {
  using X = U;
  using M = V;
  using Monoid = RangeMax< U >;
  static M op(const M &a, const M &b) { return a + b; }
  static constexpr M identity() { return 0; }
  static X actInto(const M &m, long long, const X &x) { return m + x; }
};

template < class U = long long, class V = U >
struct RangeMinSet {
  using M = U;
  using Monoid = RangeMin< U >;
  using X = typename Monoid::T;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return M(-inf_monoid); }
  static X actInto(const M &m, long long, const X &x) { return m == identity() ? x : m; }
};

template < class U = long long, class V = U >
struct RangeMaxSet {
  using M = U;
  using Monoid = RangeMax< U >;
  using X = typename Monoid::T;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return M(-inf_monoid); }
  static X actInto(const M &m, long long, const X &x) { return m == identity() ? x : m; }
};

template < class U = long long, class V = U >
struct RangeSumAdd {
  using X = U;
  using M = V;
  using Monoid = RangeSum< U >;
  static M op(const M &a, const M &b) { return a + b; }
  static constexpr M identity() { return 0; }
  static X actInto(const M &m, long long n, const X &x) { return m * n + x; }
};

template < class U = long long, class V = U >
struct RangeSumSet {
  using X = U;
  using M = V;
  using Monoid = RangeSum< U >;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return M(-inf_monoid); }
  static X actInto(const M &m, long long n, const X &x) {
    return m == identity() ? x : m * n;
  }
};

template < class U, class V = U >
struct RangeProdMul {
  using X = U;
  using M = V;
  using Monoid = RangeProd< U >;
  static M mpow(M a, long long b) {
    X r(1);
    while(b) {
      if(b & 1) r = r * a;
      a = a * a;
      b >>= 1;
    }
    return r;
  }
  static M op(const M &a, const M &b) { return a * b; }
  static constexpr M identity() { return M(1); }
  static X actInto(const M &m, long long n, const X &x) { return x * mpow(m, n); }
};

template < class U, class V = U >
struct RangeProdSet {
  using X = U;
  using M = V;
  using Monoid = RangeProd< U >;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return V::unused; }
  static X actInto(const M &m, long long n, const X &) {
    if(m == identity()) return;
    return RangeProdMul< U, V >::mpow(m, n);
  }
};

template < class U = long long, class V = U >
struct RangeOr2 {
  using X = U;
  using M = V;
  using Monoid = RangeOr< U >;
  static M op(const M &a, const M &b) { return a | b; }
  static constexpr M identity() { return M(0); }
  static X actInto(const M &m, long long, const X &x) { return m | x; }
};

template < class U = long long, class V = U >
struct RangeAnd2 {
  using X = U;
  using M = V;
  using Monoid = RangeAnd< U >;
  static M op(const M &a, const M &b) { return a & b; }
  static constexpr M identity() { return M(-1); }
  static X actInto(const M &m, long long, const X &x) { return m & x; }
};

template < class U, size_t N >
struct RangeAnd2< U, std::bitset< N > > {
  using X = U;
  using M = std::bitset< N >;
  using Monoid = RangeAnd< U >;
  static M op(const M &a, const M &b) { return a & b; }
  static constexpr M identity() { return std::bitset< N >().set(); }
  static X actInto(const M &m, long long, const X &x) { return m & x; }
};
/// }}}--- ///

using Seg = LazySegmentTree< RangeSumAdd<> >;

ll rangesum(ll a, ll b) {
  // ll sum = 0;
  // for(ll i = a; i <= b; i++) sum += i;
  // return sum;
  return (b - a + 1) * (b - a + 2) / 2 + (b - a + 1) * (a - 1);
}

int m, a, b;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> m >> a >> b;
  vector<int> v(a, -1);
  int now = 0;
  int rm = 0;
  int c = a / gcd(a, b);
  c--;
  v[0] = 0;
  while(c) {
    now += a;
    rm = max(rm, now);
    while(now - b >= 0) {
      now -= b;
      assert(now < a);
      if(v[now] < 0) v[now] = rm, c--;
      else now %= b;
    }
  }
  vector<pair<int, int>> w;
  for(int i = 0; i < a; i++) w.emplace_back(v[i], i);
  w.emplace_back(m + 1, 0);
  sort(begin(w), end(w));

  ll L = 0;
  ll ans = 0;

  Seg seg(a);

  auto calc = [&](ll L, ll R, ll g, ll num) {
    return (R - L + 1) * (g - 1) * num + seg.fold(L % a, R % a + 1);
  };

  // dump(rangesum(0, 10));
  // dump(rangesum(2, 10));
  // dump(rangesum(7, 10));

  for(int i = 0; i <= a; i++) {
    if(w[i].first == -1) continue;
    ll R = w[i].first - 1;
    R = min<ll>(R, m);
    // dump(seg.fold(0, 1));
    // dump(L, R);
    if(L <= R) {
      // dump(i);
      ll lg = L / a + 1;
      ll rg = R / a + 1;
      if(lg == rg) {
        ans += calc(L, R, lg, i);
      } else {
        if(lg + 1 <= rg - 1) ans += rangesum(lg + 1 - 1, rg - 1 - 1) * a * i + seg.fold(0, a) * (rg - lg - 2 + 1);
        ans += calc(L, lg * a - 1, lg, i);
        ans += calc(rg * a - a, R, rg, i);
      }
      L = R + 1;
    }
    if(i != a) seg.act(w[i].second, a, 1);
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORR(i,b) FOR(i, 0, b)
#define sz(e) (int)e.size()
#define CLR(x, a) memset(x, a, sizeof(x))
#define all(v) v.begin(),v.end()
#define pb push_back

typedef long long ll;

const int MAXN = 200005;

int vet[MAXN];

int dfs (int x, int maxx, int a, int b, ll limit) {
  if(vet[x]==-1) {
    vet[x] = maxx;

    if (x - b >= 0) {
      dfs (x-b, maxx, a, b, limit);
    }
    if (x + a < limit) {
      dfs (x+a, max(maxx, x+a), a, b, limit);
    }
  }
}

int main () {
  ll m, a, b;
  cin>>m>>a>>b;
  CLR (vet, -1);

  dfs(0, 0, a, b, MAXN);

  // FOR (z, 1, min(m+1, 1LL * MAXN)) {
  //   // ll k = (i * a);
  //   // ll y = k / b;
  //   // ll z = k - b * y;
  //   int aux = 0;
  //   int tmp = 0;
  //   while (tmp!=z) {
  //     if(tmp>=b) {
  //       tmp -= b;
  //     } else {
  //       tmp += a;
  //     }
  //     aux = max(tmp, aux);
  //   }
  //   // cerr << "===>" << i << " "
  //   if (aux > m) continue;
  //   while (z < MAXN && vet[z] == -1) {
  //     vet[z] = aux;
  //     z += a;
  //   }
  // }

  ll res = 0;
  FORR (i, min (m + 1, 1LL * MAXN)) {
    ll k = vet[i];
    if (vet[i]==-1) {
      continue;
    }
    // ll C = 1 + (m - k;
    res += (m-k+1);

    // ll W = (m-k)/a;

    // cerr << i << " " << k << " " << C << " " << ans[k] << " " << W << endl;
    // FOR (x, 1, W+1) {
    //   ans[k] += (m-k+1-a*x);
    // }
    // cerr << i << " " << k << " " << C << " " << ans[k] << " " << W << endl;
  }

  // FOR (i, MAXN, m) {
  //   res += m-i+1;
  // }

  if (MAXN<=m) {
    res += (m-MAXN + 1) * (m - MAXN + 2) / 2;
  }

  // FORR (i, 20) {
  //   cerr << i << " => " << vet[i] << " " <<  ans[i] << endl;
  // }

  // ll res = 0LL;
  // FORR (i, MAXN) {
  //   if (ans[i]!=-1) {
  //     res += ans[i];
  //   }
  // }

  cout << res << endl;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int, int>
#define pb push_back
#define pli pair<ll, int>
#define pil pair<int, ll>
#define clr(a, x) memset(a, x, sizeof(a))

const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define TREE tree<pli, null_type, greater<pli>, rb_tree_tag, tree_order_statistics_node_update>
TREE T;
*/

ll m, a, b, res;
int ok[200015], vis[200015];
vector<int> e[200015];
stack<int> sta;
int dfs(int x, int X) {
	vis[x] = 1; sta.push(x);
	if (ok[x]) return 1;
	for (int i = 0; i < e[x].size(); ++i) {
		int y = e[x][i];
		if (vis[y] || X < y) continue;
		if (dfs(y, X)) ok[x] = 1;
	}
	res += ok[x];
	return ok[x];
}
void dfs2(int x, int X) {
	if (x + a <= X) {
		if (!ok[x + a]) {
			res += ok[x + a] = 1;
			dfs2(x + a, X);
		}
	}
	if (0 <= x - b) {
		if (!ok[x - b]) {
			res += ok[x - b] = 1;
			dfs2(x - b, X);
		}
	}
}
ll g;
ll cal(ll m) {
	ll r = m % g, d = m / g;
	return d * (d + 1) / 2 * g + r * (g + 1);
}
int main() {
	scanf("%lld%lld%lld", &m, &a, &b);
	ll ans = 0;
	ll M = min(m, 200000ll);
	for (int i = 0; i <= M; ++i) {
		if (a <= i) e[i].pb(i - a);
		if (i + b <= M) e[i].pb(i + b);
	}
	ok[0] = 1, res = 1, ans = 1;
	for (int x = 1; x <= M; ++x) {
		if (a <= x && ok[x - a]) res += ok[x] = 1;
		if (ok[x]) dfs2(x, x);
		ans += res;
		while (sta.size()) {
			int x = sta.top(); sta.pop();
			vis[x] = 0;
		}
	}
	g = __gcd(a, b);
	ans += cal(m + 1) - cal(M + 1);
	printf("%lld\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5+10;
int f[maxn*10];
int minPos[maxn * 10];
int dp[maxn * 10];

void dfs(int u, int a,int b) {
	priority_queue<int> q;
	q.push(0);
	f[0] = true;
	minPos[0] = 0;
	while (!q.empty()) {
		int u = -q.top();
		q.pop();
		if (u + a < maxn * 10 && !f[u+a]) {
			int v = u + a;
			q.push(-v);
			minPos[v] = max(v, minPos[u]);
			f[v] = true;
		}
		//if (u == 7) cerr << "xxx " << f[u-a] << endl;
		if (u - b >= 0 && !f[u-b]) {
			int v = u - b;
			q.push(-v);
			minPos[v] = minPos[u];
			f[v] = true;
		}
		//q.pop();
	}
}

long long get(int l,int r, int t) {
	while (l%t) l++;
	if (l>r) return 0;
	return (r - l) / t + 1;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m, a, b;
	cin >> m >> a >> b;
	int t = max(a,b);
	memset(minPos, -1,sizeof(minPos));
	dfs(0, a, b);
	//cerr << "asdf" << endl;
	priority_queue<int> q;
	//for(int i=0;i<20;i++) cerr << i <<" " <<f[i] <<" " <<minPos[i] << endl;
	for(int i=0;i<maxn * 10;i++) {
		if (i) dp[i] = dp[i-1];
		if (f[i]) {
			q.push(-minPos[i]);
		}

		while (q.size() && -q.top() <=i) {
			dp[i]++;
			q.pop();
		}
	}
	//for(int i=0;i<10;i++) cout <<"ttt " << i<<" "<< dp[i] <<endl;
	long long res = 0;

	if (m > maxn * 4) {
		for(int i=0;i<maxn * 4;i++) {
			res += dp[i];
		}
		int t = __gcd(a,b);
		res += 1ll * dp[maxn * 4 - 1] * (m - maxn * 4 + 1);
		long long tmp = get(maxn * 4, m, t);
		res += (tmp * (tmp + 1)) / 2 * t;
		res -= (maxn * 4 + tmp * t -1 - m) * tmp;
	} else {
		for(int i=0;i<=m;i++) {
			res += dp[i];
		}
	}
	cout << res;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define sz(a) int(a.size())

long long sx (long long x, long long d) {
	long long q = x/d+1;
	long long ret = q*(q-1)/2*d + (x%d+1)*q;
	return ret;
}

long long sr (long long l, long long r, long long d) {
	long long ret = sx(r, d);
	if (l) ret -= sx(l-1, d);
	return ret;
}

bool vis[210010];

int curS = 0;
long long a, b;
void dfs (int id, int x) {
	if (id < 0 || id > x || vis[id]) return;
	curS++;
	vis[id] = 1;
	dfs(id+a, x), dfs(id-b, x);
}

int main() {
	long long m;
	cin >> m >> a >> b;

	if (a == 1) {
		cout << sx(m, 1) << endl;
		return 0;
	}

	if (b == 1) {
		long long ans = 0;
		if (m < a) ans = m+1;
		else ans = m+sr(a, m, 1)+1;
		cout << ans << endl;
		return 0;
	}

	if (a == b) {
		cout << sr(0, m, a) << endl;
		return 0;
	}

	long long bfAns = 0;
	long long ans = 0;

	int gcd = __gcd(a,b);
	for (int i = 0; i <= m; i++) {
		if (i < a) {
			ans++;
			continue;
		}

		if (i == a+(b-gcd)) {
			ans += sr(i, m, gcd);
			break;
		}

		curS = 0;
		memset(vis, 0, sizeof(vis));
		dfs(0, i);

		ans += curS;
	}
	cout << ans << endl;
	return 0;

}

#include <bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef pair<int, int> int2;
#define pp(a,b) push_back(make_pair((a),(b)))
#define pb push_back
#define mp make_pair
#define buybuy {printf("-1\n");return 0;}
#define PI 3.141592653589

int next() {int x; cin >> x; return x;}
lint lnext() {lint x; cin >> x; return x;}
//template<typename T> outln(T x) {cout << x; cout << "\n";}
#define prt(a) cout << a << "\n";
#define prtn(a, n) {for(int iiiiiiiiiii = 0; iiiiiiiiiii < n; iiiiiiiiiii++) cout << a[iiiiiiiiiii] << " "; cout << "\n";}
#define prtall(a) {for (auto iiiiiiiiiii : a) cout << iiiiiiiiiii << " "; cout << "\n";}

int gcd(int x, int y) {
	if (!x || !y) return x + y;
	return gcd(y % x, x);
}

int main() {
	cout.precision(20);
	ios_base::sync_with_stdio(false);

	lint m = next();
	lint a = next();
	lint b = next();

	lint inf = (int)(1e9 + 1);

	int l = max(a, b) + 1;
	vector<lint> mn(l, inf);
	mn[0] = 0;

	for (int i = 1;; i++) {
		if (i * a % b == 0) mn[b] = max(mn[(i - 1) * a % b], (i - 1) * a % b + a);
		if (mn[i * a % b] != inf) break;
		mn[i * a % b] = max(mn[(i - 1) * a % b], (i - 1) * a % b + a);
	}

	//prtn(mn, l);

	for (int i = b + 1; i < a; i++) mn[i] = mn[i - b];

	//prtn(mn, l);

	lint answ = 0;
	for (lint i = 0; i < a; i++) if (mn[i] != inf) {
		answ += max(0ll, m - mn[i] + 1);
		answ += max(0ll, m - max(i + a, mn[i]) + 1);

		if (m >= i + 2 * a) {
			lint k = (m - i) / a;
			answ += (k - 1) * ((m - (i + 2* a) + 1) + (m - (i + k * a) + 1)) / 2;
		}

		//cout << "answ after " << i << ": " << answ << "\n";
	}

	cout << answ << "\n";
}

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const deque<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {
	os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T,class U> ostream& operator<<(ostream &os, const tuple<S,T,U> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class S, class T,class U,class V> ostream& operator<<(ostream &os, const tuple<S,T,U,V> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<","<<get<3>(t)<<")";}
template<class S, class T,class U,class V,class W> ostream& operator<<(ostream &os, const tuple<S,T,U,V,W> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<","<<get<3>(t)<<","<<get<4>(t)<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
#else
#define out
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
	int m,a,b;
	cin>>m>>a>>b;
	int g=__gcd(a,b);
	priority_queue<int,vector<int>,greater<int>> pq;
	pq.emplace(0);
	const int UB=1123456;
	vector<int> inq(UB); inq[0]=1;
	vector<int> vst(UB);
	vector<int> ans(UB);
	int cnt=0;
	int mx=0;
	int ok=0;
	while(pq.size()){
		int i=pq.top(); pq.pop();
		if(mx<i){
			ans[mx]=cnt;
			if(mx>=a && ans[mx]==mx/g+1){ ok=1; break;}
			mx=i;
		}
		++cnt;
		vst[i]=1;
		if(i+a<UB && MX(inq[i+a],1)) pq.emplace(i+a);
		if(i-b>=0 && MX(inq[i-b],1)) pq.emplace(i-b);
	}
	assert(ok);
	// rep(i,30) cout<<ans[i]<<","; cout<<endl;
	rep(i,mx) MX(ans[i+1],ans[i]);
	// rep(i,30) cout<<ans[i]<<","; cout<<endl;
	ll re=0;
	rep(i,min(mx,m)+1) re+=ans[i];
	ll o=ans[mx]-mx/g;
	auto fun=
		[&](ll n,ll o,ll d){
			ll n0=n/d*d;
			ll t=n0/d;
			ll re=(o+o+t)*(t+1)/2*d;
			re+=(n-n0)*(o+t);
			return re;
		};
	if(mx<m){
		re-=fun(mx,o,g);
		re+=fun(m,o,g);
	}
	cout<<re<<endl;
  return 0;
}

/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
LL a[SIZE],dp[SIZE][3],an;
int main(){
    int n; LL x; R(n,x);
    FOR(i,1,n){
        R(a[i]);
    }
    FOR(i,1,n){
        dp[i][0]=max({a[i],0LL,dp[i-1][0]+a[i]});
        dp[i][1]=max({0LL,a[i]*x,dp[i-1][1]+a[i]*x,dp[i-1][0]+a[i]*x});
        dp[i][2]=max({0LL,a[i],dp[i-1][1]+a[i],dp[i-1][2]+a[i],dp[i-1][0]+a[i]});
        REP(j,3)an=max(an,dp[i][j]);
    }
    W(an);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long INT;

int vst[600600]={1};

main() {
#ifndef	ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	INT n, a, b; cin>>n>>a>>b;

	INT ans=0;
	for(int i=0; i<=n && i<a; i++) ans++;

	INT g=a%b, sum=1;
	for(int i=a; i<=n && i<a+b; i++) {
		if((i-a)%g==0) {
			queue<int> q;
			q.push(i); vst[i]=1;
			while(!q.empty()) {
				int u=q.front(); q.pop();
				sum++;
				int v=u+a;
				if(v<=i && !vst[v]) vst[v]=1, q.push(v);
				v=u-b;
				if(v>=0 && !vst[v]) vst[v]=1, q.push(v);
			}
		}
		ans+=sum;
	}

	g=__gcd(a, b);
	if(a+b<=n) {
		INT st=(a+b)/g+1, ed=n/g+1;
		ans+=((st+ed)*(ed-st+1)/2)*g;
		ans-=(g-n%g-1)*ed;
	}
	printf("%I64d", ans);
}

#pragma comment(linker, "/STACK:512000000")
#include <bits/stdc++.h>
#ifdef AIM
#include <sys/resource.h>
#endif
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(__attribute__((unused)) bool);
void precalc();
clock_t start;
#define FILENAME ""

int main() {
#ifdef AIM
  string s = FILENAME;
//    assert(!s.empty());
  freopen("/home/alexandero/ClionProjects/cryptozoology/input.txt", "r", stdin);
//freopen("/home/alexandero/ClionProjects/cryptozoology/output.txt", "w", stdout);
#else
//    freopen(FILENAME ".in", "r", stdin);
//    freopen(FILENAME ".out", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
#ifndef AIM
  cout.sync_with_stdio(0);
  cin.tie(0);
#endif

#ifdef AIM
  const rlim_t kStackSize = 256 * 1024 * 1024;
  struct rlimit rl;
  int result;

  result = getrlimit(RLIMIT_STACK, &rl);
  if (result == 0)
  {
    if (rl.rlim_cur < kStackSize)
    {
      rl.rlim_cur = kStackSize;
      result = setrlimit(RLIMIT_STACK, &rl);
      if (result != 0)
      {
        fprintf(stderr, "setrlimit returned result = %d\n", result);
      }
    }
  }
#endif

  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
      //cout << "Case #" << testNum++ << ": ";
      solve(true);
  }
  cout.flush();
#ifdef AIM1
    while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cout.flush();
  auto end = clock();

  usleep(10000);
  print_stats(end - start);
  usleep(10000);
#endif

    return 0;
}

template<typename T>
T binpow(T q, T w, T mod) {
    if (!w)
        return 1 % mod;
    if (w & 1)
        return q * 1LL * binpow(q, w - 1, mod) % mod;
    return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
    while (w) {
        q %= w;
        swap(q, w);
    }
    return q;
}
template<typename T>
T lcm(T q, T w) {
    return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
    sort(all(a));
    a.erase(unique(all(a)), a.end());
}

template<typename T>
void relax_min(T& cur, T val) {
    cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
    cur = max(cur, val);
}

void precalc() {
}

//#define int li
//const int mod = 1000000007;

const int C = 3000500;
char used[C];
char new_border[C];

void solve(__attribute__((unused)) bool read) {
  int a, b;
  li m;
  cin >> m >> a >> b;
  int g = gcd(a, b);
  used[0] = true;
  new_border[a] = true;
  li cur_res = 1;
  li x = 0;
  li ans = 0;
  for (int pos = 1; pos < C; ++pos) {
    if (!new_border[pos]) {
      continue;
    }
    li coord = pos;
    if (coord > m) {
      ans += (m + 1 - x) * cur_res;
      x = m + 1;
      break;
    }
    ans += (coord - x) * cur_res;
    used[coord] = true;
    queue<int> q;
    q.push(coord);
    used[coord] = true;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      if (v + a > coord && v + a < C) {
        new_border[v + a] = true;
      }
      ++cur_res;
      if (v + a <= coord && !used[v + a]) {
        used[v + a] = true;
        q.push(v + a);
      }
      if (v >= b && !used[v - b]) {
        q.push(v - b);
        used[v - b] = true;
      }
    }
    x = coord;
    //cout << x << " " << cur_res << " " << ans << endl;
  }
  if (x <= m) {
    li last_ans = m / g + 1;
    //cout << x << " " << m << " " << ans << " " << last_ans << endl;
    while (m % g) {
      ans += last_ans;
      --m;
    }
    ans += last_ans;
    assert(cur_res == x / g + 1 && cur_res <= last_ans);
    ans += (last_ans - 1) * last_ans / 2 - (cur_res - 1) * cur_res / 2;
  }
  cout << ans << endl;
}

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
	long long m, a, b;
	cin >> m >> a >> b;
	const long long bruteless = 200000;
	long long res = 0;
	long long d = __gcd(a, b);
	long long first = -1;
	for (int i = bruteless + 1; i <= m; i++) {
		if (i % d == 0) {
			first = i;
			break;
		}
	}
	long long numOf = (m/d) - (bruteless/d);
	if (first != -1) {
		res = ((m - first) + (m - first - ((numOf - 1) * d)) * numOf) / 2;
	}

	long long firstApp[bruteless+1];
	for (int i = 1; i <= bruteless; i++) {
		firstApp[i] = -1;
	}
	firstApp[0] = 0;
	queue<int> done;
	done.push(0);
	while (!done.empty()) {
		int temp = done.front();
		done.pop();
		if (temp + a <= bruteless) {
			if (firstApp[temp+a] == -1) {
				firstApp[temp+a] = max(firstApp[temp], temp+a);
				done.push(temp+a);
			}
			else {
				if (firstApp[temp + a] > max(firstApp[temp], temp+a)) {
					done.push(temp+a);
				}
				firstApp[temp+a] = min(max(firstApp[temp], temp+a), firstApp[temp+a]);
			}
		}
		if (temp - b >= 0) {
			if (firstApp[temp-b] == -1) {
				firstApp[temp-b] = firstApp[temp];
				done.push(temp-b);
			}
			else {
				if (firstApp[temp - b] > firstApp[temp]) {
					done.push(temp-b);
				}
				firstApp[temp-b] = min(firstApp[temp], firstApp[temp-b]);
			}
		}
	}
	for (int i = 0; i <= min(m, bruteless); i++) {
		if (firstApp[i] != -1 && firstApp[i] <= m) {
			res += (long long)(m - firstApp[i] + 1);
		}
	}

	cout << res;
}

/**************************************************************
    Problem: ????
    User: Big_Red_Dates
    Language: GNU_C++11
    Result: Accepted
    Time:0 ms
    Memory:0 kb
    length:0 kb
    score: inf
****************************************************************/
//CLOCKS_PER_SEC
using namespace std;
#include<bitset>
#include<deque>
#include<stdint.h>
#include<set>
#include<stack>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<ctime>
#include<map>
#define sqr(x) (x)*(x)
#define sort stable_sort
#define ll long long
#define mk make_pair
#define pb push_back
#define in insert
#define mtr(x,y,z) mk(mk(x,y),z)
#define fi first
#define se second
#define lch(x) ((x)<<1)
#define rch(x) (((x)<<1)|1)
#define all(x) (x).begin(),(x).end()
#define titose CLOCKS_PER_SEC
#define fpi(x) freopen(x,"r",stdin);
#define fpo(x) freopen(x,"w",stdout);
#define fprio fpi("in.txt");fpo("out.txt");
#define fast ios_base::sync_with_stdio(false);
inline void read(int &x){int v=0,f=1;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=v*10+c-'0';while (isdigit(c=getchar())) v=v*10+c-'0';x=v*f;}
inline void read(ll &x){ll v=0ll,f=1ll;char c=getchar();while (!isdigit(c)&&c!='-') c=getchar();if (c=='-') f=-1; else v=v*10+c-'0';while (isdigit(c=getchar())) v=v*10+c-'0';x=v*f;}
inline void readc(char &x){char c;while ((c=getchar())==' ');x=c;}
inline void writes(string s){puts(s.c_str());}
inline void writeln(){writes("");}
inline void writei(int x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
inline void writell(ll x){if (x<0){putchar('-');x=abs(x);}if (!x) putchar('0');char a[25];int top=0;while (x){a[++top]=(x%10)+'0';x/=10;}while (top){putchar(a[top]);top--;}}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define sl set<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define msi map<string,int>
#define msl map<string,ll>
#define piii pair<int,pii >
#define piipi pair<pii,int>
#define plll pair<ll,pll >
#define pllpl pair<pll,ll>
#define pqi priority_queue<int>
#define pql priority_queue<ll>
#define npqi priority_queue<int,vector<int>,greater<int> >
#define npql priority_queue<ll,vector<ll>,greater<ll> >
#define forup(i,csc,lys) for ((i)=(csc);(i)<=(lys);(i)++)
#define fordo(i,csc,lys) for ((i)=(csc);(i)>=(lys);(i)--)
#define rep(i,x) forup ((i),1,(x))
#define repd(i,x) fordo ((i),(x),1)
#define itr iterator
#define lyscsc(itcalc,c) for(__typeof((c).begin()) itcalc=(c).begin();itcalc!=(c).end();itcalc++)
#define NO {cout<<":(";return 0;}
#define YES {cout<<"YES";return 0;}
#define y0 y000000000000000000000000000
#define y1 y111111111111111111111111111
#define j0 j000000000000000000000000000
#define j1 j111111111111111111111111111
#define cl0(a) memset((a),(0),(sizeof((a))))
#define clz(a) memset((a),(0x16),(sizeof((a))))
#define clf(a) memset((a),(-(0x16)),(sizeof((a))))
#define inf 0x3bbbbbbb
#define lnf 0x1bbbbbbbbbbbbbbbll
#define sqrt divi
#define p2(i) (1ll<<(i))
#define readi read
#define readll read
/*************************************************/
ll n,m,i,j,ans,g,a,b,vis[200005],s,dis[200005];
ll solve(ll x,ll g)
{
	x++;
	ll t=x/g;
	ll s=g*t*(t+1)/2;
	s+=(x-t*g)*(t+1);
	return s;
}
ll solve(ll l,ll r,ll g)
{
	return solve(r,g)-solve(l-1,g);
}
priority_queue<pair<ll,ll> > pq;
ll upd(ll x,ll y)
{
	if (dis[x]>y)
	{
		dis[x]=y;
		pq.push(mk(-y,x));
	}
}
ll f(ll x)
{
	int i;
	while (!pq.empty()&&pq.top().fi==-x)
	{
		ll t=pq.top().se;pq.pop();if (dis[t]!=x) continue;s++;
		if (t-b>=0) upd(t-b,x);
		if (t+a<=200000) upd(t+a,max(t+a,x));
	}
	return s;
}
int main()
{
	fast;
//	while (cin>>n>>g) cerr<<solve(n,g)<<endl;
	cin>>n>>a>>b;g=__gcd(a,b);a/=g;b/=g;
	pq.push(mk(0,0));clz(dis);dis[0]=0;
	for (i=0;i<=200000&&i<=n;i++)
	{
		ans+=f(i);
	}
	if (n>200000)
	{
		ans+=solve(200001,n,g);
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
const ll INF=LLONG_MAX,MOD=1e9+7;
const int L=17,N=1<<L;

ll d[1111111];
ll m,a,b;

ll gcd(ll x,ll y){
	if(y==0){
		return x;
	}
	return gcd(y,x%y);
}

ll som(ll x, ll y){
	return (x+y)*(y-x+1)/2;
}

ll fill(ll k, ll i){
	ll cnt=1;
	d[k]=i;
	// cout << k << " "<<i <<endl;
	if(k-b>=0 && (d[k-b]==m+1)){
		cnt+=fill(k-b,i);
	}
	if(k+a<=i && (d[k+a]==m+1)){
		cnt+=fill(k+a,i);
	}
	return cnt;
}

int main(){
	ios::sync_with_stdio(false);
	cin>>m>>a>>b;
	d[0]=0;
	for(int i=1;i<1111111;i++){
		d[i]=m+1;
	}
	ll g=gcd(a,b);
	ll i=g;
	ll cnt=1;
	while(i<=m){
		// cout<<i<<":"<<cnt<<endl;
		if(i-a>=0 && d[i-a]!=m+1){
			cnt+=fill(i,i);
			if(cnt-1==i/g){
				break;
			}
		}
		i+=g;
	}
	// cout<<"i:"<<i<<endl;
	if(i>m){
		ll ans=0;
		for(ll j=0;j<=m;j++){
			ans+=(m-d[j]+1);
		}
		cout<<ans<<endl;return 0;
	}
	ll ans=0;
	for(ll j=0;j<i;j+=g){
		// cout<<d[j]<<endl;
		ans+=(m-d[j]+1)*g;
	}
	// cout<<ans<<"AAA"<<endl;
	ll mm = m/g*g;
	ans+=((mm-i)/g+2)*((mm-i)/g+1)/2*g-g;
	// cout<<ans<<"BBB"<<endl;
	ans += (m-mm+1)*(m-mm+2)/2;
	cout<<ans<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d ",x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define pf2(x,y) printf("%d %d ",x,y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define pf3(x,y,z) printf("%d %d %d ",x,y,z)
#define sfc(c) scanf(" %c",&c)
#define pfc(c) printf("%c",c)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define INF 1000000008
#define LLINF ll(1e18+10)
#define ENDL puts("")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef unsigned int uint;
typedef long double ld;

template<class T>
void printVector(T begin, T end)
{
    for(auto i=begin; i!=end; i++)
    {
        cout<<*i<<' ';
    }
    cout<<endl;
}

ll readLL() {
    ll x;
    cin >> x;
    return x;
}

int readInt() {
    int x;
    cin >> x;
    return x;
}

int gcd(int a, int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}

bool u[500300];
ll cnt=1;
ll res=0;
int m,a,b;

void dfs(int v, int l, int r)
{
    u[v]=1;
    cnt++;
    if(v+a<=r)
    {
        if(!u[v+a])
        {
            dfs(v+a,l,r);
        }
    }
    if(v-b>=0)
    {
        if(!u[v-b])
        {
            dfs(v-b,l,r);
        }
    }
}

int main()
{
    /*
    freopen("caravan.in","r",stdin);
    freopen("caravan.out","w",stdout);
    /**/

    u[0]=1;

    sf3(m,a,b);
    int g=gcd(a,b);
    int i=0;
    for(i=0; i<=min(m,300000); i++)
    {
        if(i-a>=0&&u[i-a])
        {
            dfs(i,0,i);
        }
        res+=cnt;
    }
    while(i<=m&&i%g!=0)
    {
        if(i-a>=0&&u[i-a])
        {
            dfs(i,0,i);
        }
        res+=cnt;
        i++;
    }
    ll tmp=(m-i)/g+1;
    res+=(ll)cnt*tmp+tmp*(tmp+1)/2;
    cout<<res;

    return 0;

}

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>

#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;

set <ll> q;
bool used[201000];

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    ll i,n,m,a,b,cnt = 0, ans = 0,x,l,r,g;
    cin >> m >> a >> b;
    q.insert(0);
    used[0] = true;
    for (i = 0; i < min(m + 1, a + b); i++)
    {
        while (!q.empty() && *q.begin() <= i)
        {
            x = *q.begin();
            q.erase(q.begin());
            cnt++;
            if (x - b > 0 && !used[x - b])
            {
                q.insert(x - b);
                used[x - b] = true;
            }
            if (x + a < a + b && !used[x + a])
            {
                q.insert(x + a);
                used[x + a] = true;
            }
        }
        ans += cnt;
    }
    g = gcd(a, b);
    l = a + b + g;
    r = m - m % g + g;
    if (m < a + b)
        cout << ans;
    else
        cout << ans + (l + r) * ((r - l) / g + 1) / 2;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

int gcd(int x, int y){
	return y == 0 ? x : gcd(y, x % y);
}

int rec[N << 1], cnt[N << 1];

int main(){
	int m, a, b, now, tot, maxx, _gcd, rem;
	long long ans;
	cin >> m >> a >> b;
	_gcd = gcd(a, b);
	a /= _gcd;
	b /= _gcd;
	now = 0; tot = 1; maxx = 0;
	while (tot < a + b){
		if (now >= b) now -= b;
		else{
			now += a;
			maxx = max(maxx, now);
		}
		rec[now] = maxx;
		tot++;
	}
	for (int i = 0; i <= a + b - 1; i++) cnt[rec[i]]++;
	for (int i = 1; i <= a + b - 1; i++) cnt[i] += cnt[i - 1];
	ans = 0;
	if (m >= (a + b - 1) * _gcd){
		for (int i = 0; i <= a + b - 1; i++) ans += cnt[i] * _gcd;
		ans += 1LL * ((a + b - 1) * _gcd + 3 + m) * (m - (a + b - 1) * _gcd) / 2;
	}
	else{
		rem = m % _gcd;
		m /= _gcd;
		for (int i = 0; i <= m; i++) ans += cnt[i] * _gcd;
		ans -= cnt[m] * (_gcd - rem - 1);
	}
	cout << ans << '\n';
	return 0;
}

#include <bits/stdc++.h>
#define MOD 1000000007
#define NMAX 200005
#define INF 0x3f3f3f3f
#define pb push_back

using namespace std;

typedef pair<int, int> pii;

int viz[NMAX],a,b;

long long gauss(long long n) {
    return n*(n+1)/2;
}

long long f = 1;
void dfs(int u, int bd) {
	viz[u] = true;
	++f;
	if (u - b >= 0 && !viz[u - b])
		dfs(u - b, bd);

	if (u + a <= bd && !viz[u + a])
		dfs(u + a, bd);
}

int main() {
	int n,m,i,x,y;

//	freopen("fisier.in", "r", stdin);
//	freopen("fisier.out","w", stdout);

	cin>>m>>a>>b;
	n = min(a+b,m);

	long long ans=0;
	viz[0]=1;
	for(i=0;i<=n;++i) {
		if(i-a>=0 && viz[i - a])
		  dfs(i, i);

		ans += f;
	}

	int gcd = __gcd(a,b);

	if(n != m) {
		while((m+1)%gcd != 0) {
			ans+=m/gcd+1;
			--m;
		}

		ans+=gcd*(gauss(m/gcd+1)-gauss(n/gcd+1));
	}

	cout << ans;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
const ll INF=LLONG_MAX,MOD=1e9+7;
const int L=17,N=1<<L;

ll d[1111111];
ll m,a,b;

ll gcd(ll x,ll y){
	if(y==0){
		return x;
	}
	return gcd(y,x%y);
}

ll som(ll x, ll y){
	return (x+y)*(y-x+1)/2;
}

ll fill(ll k, ll i){
	ll cnt=1;
	d[k]=i;
	// cout << k << " "<<i <<endl;
	if(k-b>=0 && (d[k-b]==m+1)){
		cnt+=fill(k-b,i);
	}
	if(k+a<=i && (d[k+a]==m+1)){
		cnt+=fill(k+a,i);
	}
	return cnt;
}

int main(){
	ios::sync_with_stdio(false);
	cin>>m>>a>>b;
	d[0]=0;
	for(int i=1;i<1111111;i++){
		d[i]=m+1;
	}
	ll g=gcd(a,b);
	ll i=g;
	ll cnt=1;
	while(i<=m){
		// cout<<i<<":"<<cnt<<endl;
		if(i-a>=0 && d[i-a]!=m+1){
			cnt+=fill(i,i);
			if(cnt-1==i/g){
				break;
			}
		}
		i+=g;
	}
	// cout<<"i:"<<i<<endl;
	if(i>m){
		ll ans=0;
		for(ll j=0;j<=m;j++){
			ans+=(m-d[j]+1);
		}
		cout<<ans<<endl;return 0;
	}
	ll ans=0;
	for(ll j=0;j<i;j+=g){
		cout<<d[j]<<endl;
		ans+=(m-d[j]+1)*g;
	}
	// cout<<ans<<"AAA"<<endl;
	ll mm = m/g*g;
	ans+=((mm-i)/g+2)*((mm-i)/g+1)/2*g-g;
	// cout<<ans<<"BBB"<<endl;
	ans += (m-mm+1)*(m-mm+2)/2;
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define endl "\n"

const ll N = 1e6 + 7;
const ll mod = 1e9 + 7;

ll gcd(ll a, ll b)
{
    if(b == 0)
        return a;
    return gcd(b, a%b);
}

map<ll,ll> mp;

int32_t main()
{

    IOS

    ll i = 1;
    vector<ll> v;

    ll n, a, b, m;

    cin>>m>>a>>b;

    ll k = gcd(a, b);
    ll z = m / k;

    ll val1 = m*z - (k*z*(z+1)/2) + z + m + 1;
    ll val2 = 0;
    ll start = 0;
    ll cnt = 0;
    ll ans = 0;
    ll currmx = 0;
    while(1)
    {
        if(start < a && !mp[start])
        {
            cnt++;
            mp[start] = 1;
        }
        currmx = max(currmx, start);
        if(start <= m)
            ans += min(currmx, m + 1) - start;
        if(start >= b)
            start -= b;
        else
            start += a;
        if(cnt >= a/k)
            break;
    }

    cout<<val1 - ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define int long long
using namespace std;
int m, a, b, res = 0, ans[1000001], fix[1000001];
set<pair<int, int>> s;
int sm(int x) { return (x < 0) ? 0 : x * (x + 1) / 2; }
main() {
  cin >> m >> a >> b;
  for (int i = 1; i <= a + b; i++)
    ans[i] = 1e18;
  s.insert({0, 0});
  while (s.size()) {
    auto x = s.begin();
    if ((x->first) < 0 || (x->first) > min(m, a + b) || fix[x->first]) {
      s.erase(s.begin());
      continue;
    }
    if ((x->first) < (x->second))
      ans[x->first] = min(ans[x->first], x->second);
    else
      ans[x->first] = (x->first);
    s.insert({(x->first) + a, ans[(x->first)]});
    if ((x->first) > b)
      s.insert({(x->first) - b, ans[(x->first)]});
    fix[x->first] = 1;
    s.erase(x);
  }
  res = 0;
  for (int i = 0; i <= min(m, a + b); i++) {
    ans[i] = max(i, ans[i]);
    if (ans[i] <= m)
      res += m - ans[i] + 1;
  }
  cout << res + sm(m - a - b);
}

#include<bits/stdc++.h>
using namespace std;
long long n;
long long a,b,sum;
long long c[200007];
long long d[200007];
int vis[200007];
priority_queue<pair<long long,long long> >pq;
int main(){
    scanf("%lld%lld%lld",&n,&a,&b);
    sum=a+b;
    long long gcd=__gcd(a,b);
    long long ans=0;
    if(n>sum){
        long long tmp=n/gcd;
        ans=gcd*(sum/gcd+tmp+1)*(tmp-sum/gcd)/2;
        for(long long i=tmp*gcd;i<=n;++i)
            ans+=tmp+1;
    }
    memset(c,0x3f3f3f3f,sizeof(c));
    pq.push(make_pair(0,0));
    c[0]=0;
    while(!pq.empty()){
        long long x=pq.top().second;
        pq.pop();
        if(vis[x])
            continue;
        else
            vis[x]=1;
        if(x+a<sum){
            if(c[x+a]>max(c[x],x+a)){
                c[x+a]=max(c[x],x+a);
                pq.push({-c[x+a],x+a});
            }
        }
        if(x>=b){
            if(c[x-b]>c[x]){
                c[x-b]=c[x];
                pq.push({-c[x-b],x-b});
            }
        }
    }
    for(int i=0;i<sum&&i<=n;++i)
        if(c[i]<sum)
            d[c[i]]++;
    for(int i=0;i<sum&&i<=n;++i){
        d[i]+=d[i-1];
        ans+=d[i];
    }
    printf("%lld",ans);
    return 0;
}

# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;

long long n, a, b;
long long d[200005];

inline long long f(long long x) {
    long long res = x;
    res *= (x + 1ll);
    res /= 2ll;
    return res;
}

void dij() {
    for (int i = 0; i <= n; ++i)
        d[i] = 1e9;
    d[0] = 0;
    set<pair<int, int> > s;
    s.clear();
    s.insert(make_pair(0, 0));
    int len;
    while (!s.empty()) {
        int x = s.begin()->second;
        s.erase(s.begin());
        if (x - b >= 0) {
            len = d[x];
            if (len < d[x - b]) {
                s.erase(make_pair(d[x - b], x - b));
                d[x - b] = len;
                s.insert(make_pair(d[x - b], x - b));
            }
        }
        if (x + a <= n) {
            len = max(d[x], x + a);
            if (len < d[x + a]) {
                s.erase(make_pair(d[x + a], x + a));
                d[x + a] = len;
                s.insert(make_pair(d[x + a], x + a));
            }
        }
    }
    return;
}

inline long long gcd(long long x, long long y) {
    while (x > 0 && y > 0) {
        if (x > y) x %= y;
        else y %= x;
    }
    return x + y;
}

inline long long get(int x, int y) {
    ++x;
    long long z = x / y;
    long long res = f(z);
    res *= y;
    while (x / y != z) {
        res += (x / y) + 1;
        --x;
    }
    return res;
}

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> a >> b;
    long long res = 0;
    if (n >= a + b) {
//        res += n - a + b;
        res += get(n, gcd(a, b));
        res -= get(a + b, gcd(a, b));
    }
    n = min(n, a + b);
    dij();
    for (int i = 0; i <= n; ++i)
        if (d[i] < 1e9) res += n - d[i] + 1;
    cout << res << '\n';
}

#include<bits/stdc++.h>
using namespace std;
#define N 300009
#define ll long long
int dist[N],dis[N],vis[N];
ll f[N];
priority_queue< pair<int,int> >que;
int gcd(int u,int v)
{
	if(v==0) return u;
	int t=u,f=v;
	u=v;
	v=t%f;
	return gcd(u,v);
}
int main()
{
	int m,a,b,n;
	scanf("%d%d%d",&m,&a,&b);
	n=2*a+b;
	memset(dist,63,sizeof dist);
	dist[0]=0;
	que.push({0,0});
	while(!que.empty())
	{
		int x=que.top().second;
		vis[x]=1;
		if(x>=b && dist[x-b]>dist[x])
		{
			dist[x-b]=dist[x];
			que.push({-dist[x-b],x-b});
		}
		if(x+a<=n && dist[x+a]> max(x+a,dist[x]))
		{
			dist[x+a]=max(x+a,dist[x]);
			que.push({-dist[x+a],x+a});
		}
		while(!que.empty() && vis[que.top().second]) que.pop();
	}
	ll ans=0;
	int mn=min(m,a+b-1);
	for(int i=0;i<=mn;++i)
		ans+=max(0,mn-dist[i]+1);
	if(m>=a+b)
	{
		int s=a/gcd(a,b);
		memcpy(dis,dist,sizeof dist);
		sort(dis,dis+n);
		ll nowf=0;
		for(int i=0,p=0,tot=0;i<n;++i)
		{
			while(p!=n && dis[p]-1<=i)
			{
				++tot;
				nowf-=dis[p]-1;
				++p;
			}
		}
		for(int i=n-1;i;--i)
			f[i]-=f[i-1];
		for(int fl=a+b,fr=(m-b%a)/a*a+b%a;fl<a+a+b;++fl,++fr)
		{
			if(fr>m) fr-=a;
			int l=fl/a,r=fr/a;
			ans+=1ll*(r-l+1)*f[fl]+1ll*(r-l+1)*(r-l)/2*s;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>

#define setIO(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

#define N 1000010

using namespace std;

typedef long long ll;

int head[N], to[N << 1], nxt[N << 1], tot, dis[N];

inline void add(int x, int y) {
	// cout << x << ' ' << y << endl ;
	to[ ++ tot] = y;
	nxt[tot] = head[x];
	head[x] = tot;
}

bool vis[N];

int ans = 0;

void dfs(int p) {
	if (!vis[p]) {
		vis[p] = true;
		// printf("QQQQQQQ %d\n", p);
		ans ++ ;
	}
	for (int i = head[p]; i; i = nxt[i]) {
		if (!vis[to[i]]) {
			dfs(to[i]);
		}
	}
}

int main() {
	// setIO("b");
	int x, a, b;
	cin >> x >> a >> b ;
	if (x >= a + b) {
		int d = __gcd(a, b);
		cout << (ll)d * (x / d) * (x / d + 1) / 2 + x / d + 1 << endl ;
		return 0;
	}
	vis[0] = 1, ans = 1;
	ll Answer = 1;
	for (int i = 1; i <= x; i ++ ) {
		int pre, aft;
		pre = i - a;
		aft = i - b;
		if (pre >= 0) {
			add(pre, i);
		}
		if (aft >= 0) {
			add(i, aft);
		}
		if (vis[pre]) {
			dfs(pre), dfs(i);
		}
		// if (pre >= 0) {
		// 	if (aft >= 0) {
		// 		add(pre, i), add(i, aft);
		// 		if (vis[pre]) {
		// 			dfs(pre), dfs(i);
		// 		}
		// 	}
		// }
		// printf("Fuck %d : %d\n", i, ans);
		Answer += ans;
	}
	cout << Answer << endl ;
	// fclose(stdin), fclose(stdout);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long ll;
typedef long double ld;

const int MaxN = 1e6;
int t[MaxN];
int m, a, b;

ll sum(int n) {return (ll)n * (n + 1) / 2;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> m >> a >> b;
    int g = __gcd(a, b);

    for (int i = 0; i < MaxN; i++) t[i] = -1;

    priority_queue<pair<int, int>> pq;
    pq.push({0, 0});

    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();

        int mx = -p.first, i = -p.second;
        if (i >= MaxN) continue;
        if (i < 0) continue;

        if (t[i] != -1) assert(t[i] <= mx);
        if (t[i] != -1) continue;

        t[i] = mx;
        pq.push({-t[i], -(i - b)});
        pq.push({-max(t[i], i + a), -(i + a)});
    }

    ll sol = 0;

    int bound = (MaxN) / g * g - 1;
    for (int i = 0; i <= min(m, bound); i++)
        sol += max(m - t[i] + 1, 0);

    if (m > MaxN - 1) {
        int lo = bound + 1, hi = m;
        //sol += (ll)(m + 1) * (hi - lo + 1) - (sum(hi) - sum(lo - 1));

        int hi2 = hi / g * g - 1;
        sol += ((ll)(m + 1) * (hi/g - lo/g + 1) - (sum(hi/g) - sum(lo/g - 1))) * g;
        sol += (ll)(m - (hi2 + 1) + 1) * (hi - (hi2 + 1) + 1);
    }

    cout << sol;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int THR = 1000000;

int gcd(int a, int b)
{
    return a ? gcd(b % a, a) : b;
}

int m, a, b;
bool chk[THR + 1];

int t;
int f(int x)
{
    int r = 1;
    chk[x] = 1;
    if(x + a <= t && !chk[x + a])
        r += f(x + a);
    if(x - b >= 0 && !chk[x - b])
        r += f(x - b);
    return r;
}

void f2(int x)
{
    chk[x] = 0;
    if(x + a <= t && chk[x + a])
        f2(x + a);
    if(x - b >= 0 && chk[x - b])
        f2(x - b);
}

int solve(int x)
{
    t = x;
    int r = f(0);
    f2(0);
    return r;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    scanf("%d%d%d", &m, &a, &b);

    int gab = gcd(a, b);

    int s = 1;
    int g = min(m, THR);
    int pm;
    while(s <= g)
    {
        int x = (s + g) / 2;
        int t = solve(x);

        if(s == g)
        {
            if(t != x / gab + 1)
            {
                assert(s == m);
                pm = s + 1;
            }
            else
                pm = s;

            break;
        }

        if(t == x / gab + 1)
            g = x;
        else
            s = x + 1;
    }

    long long r = 0;

    int p = 0;
    int v = 1;
    while(p < pm)
    {
        int s = p;
        int g = pm - 1;
        while(s < g)
        {
            int x = (s + g + 1) / 2;
            int t = solve(x);

            if(t == v)
                s = x;
            else
                g = x - 1;
        }

        r += 1LL * (s - p + 1) * v;

        if(p == pm - 1)
            break;

        p = s + 1;
        v = solve(p);
    }

    r += (1LL * m / gab * (m / gab + 1) / 2 - 1LL * pm / gab * (pm / gab - 1) / 2 + (m / gab - pm / gab + 1)) * gab;
    r -= 1LL * m / gab * (gab - m % gab - 1);

    printf("%lld\n", r);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 10000000
#define N M+10
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,a,b,d[N];
bool flag[N];
struct data
{
	int x,d;
	bool operator <(const data&a) const
	{
		return d>a.d;
	}
};
priority_queue<data> q;
void dij()
{
	memset(d,42,sizeof(d));d[0]=0;
	q.push((data){0,0});
	for (;;)
	{
		while (!q.empty()&&flag[q.top().x]) q.pop();
		if (q.empty()) break;
		data x=q.top();q.pop();
		flag[x.x]=1;
		if (x.x>=b&&d[x.x-b]>x.d)
		{
			d[x.x-b]=x.d;
			q.push((data){x.x-b,d[x.x-b]});
		}
		if (x.x+a<=M&&d[x.x+a]>max(x.x+a,x.d))
		{
			d[x.x+a]=max(x.x+a,x.d);
			q.push((data){x.x+a,d[x.x+a]});
		}
	}
	/*int head=0,tail=1;q[1]=0;flag[0]=1;
	do
	{
		int x=q[++head];
		if (x>=b&&!flag[x-b])
		{
			q[++tail]=x-b;
			flag[x-b]=1;
			d[x-b]=d[x];
		}
		if (x+a<=1000000&&!flag[x+a])
		{
			q[++tail]=x+a;
			flag[x+a]=1;
			d[x+a]=max(d[x],x+a);
		}
	}while (head<tail);*/
}
signed main()
{
	n=read(),a=read(),b=read();
	dij();
	ll ans=0;
	for (int i=0;i<=min(n,M);i++) ans+=max(0,n-d[i]+1);
	int u=gcd(a,b);n-=d[u]-u;
	if (n>M)
	{
		int cnt=n/u-M/u;
		ans+=1ll*cnt*(n+1);
		int l,r;
		for (l=M+1;l<=n;l++) if (l%u==0) break;
		for (r=n;r>M;r--) if (r%u==0) break;
		ans-=1ll*(l+r)*cnt/2;
	}
	//��i (i=1000001~n,i%u==0)
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define sz size()
#define pb push_back

const int N = 5*1e5 + 10;
const int M = 1e6 + 10;
const int inf = 1e9;
const int mod = 1e9 +7;

int n, a, b, ans, added;
bool u[N];

void tryIt(int v, int & mx)
{
    added++;
    u[v] = 1;

    if(v + a <= mx && !u[v+a])
    {
        tryIt(v+a, mx);
    }

    if(v - b > 0 && !u[v-b])
    {
        tryIt(v-b, mx);
    }

    return;
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> a >> b;

    int to = min(n, 3*max(a,b));

    ans = n+1;
    u[0] = 1;

    for(int i = 1; i <= to; i++)
    {
        if(i-a > -1 && u[i-a])
        {
            tryIt(i, i);
        }

        ans += (n-i+1)*added;

        added = 0;
    }

    if(to == n)
    {
        cout << ans;

        return 0;
    }

    int g = __gcd(a, b);

    int cnt = (n - to)/g;

    ans += (cnt*(cnt-1))/2;

    ans += (n%g+1)*cnt;

    cout << ans;
}

#include <bits/stdc++.h>
#include <complex>

#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define M_PI 3.14159265358979323846

typedef long long ll;
typedef long double ld;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//typedef complex<long double> base;
const int NUM = 500 + 5;
const ll mod = 1e9 + 7;
const ll INF = 1e18;

ll gcd (ll a, ll b, ll & x, ll & y) {
    if (a == 0) {
        x = 0; y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

ll inv(ll a, ll m){
    ll x, y;
    ll g = gcd (a, m, x, y);
    if (g != 1)
        return -1;
    x = (x % m + m) % m;
    return x;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll m, a, b;
    cin >> m >> a >> b;
    map<ll, ll> f;
    ll pos = 0;
    ll mx = 0;
    for (ll i = 0; i < a; i++){
        if (!f.count(pos % a))
            f[pos % a] = mx;
        if (pos < b)
            pos += a;
        mx = max(mx, pos);
        pos -= b;
    }
    ll ans = 0;
    for (ll i = 0; i < a; i++){
        if (!f.count(i))
            continue;
        ll x0 = f[i];
        if (x0 > m)
            continue;
        ll t = x0;
        if ((t - i) % a)
            t += a - (t - i) % a;
        ll k = (m - t) / a;
        ll su = m * (k + 1) + k + 1 - (k + 1) * t - a * k * (k + 1) / 2;
        if (t > m)
            su = 0, t = min(t, m + 1);
        if (t > 0)
            su += (m - x0 + 1) * ((t - i - 1) / a + 1);
        ans += max(0ll, su);
    }
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef double db;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pct __builtin_popcount

#define INF 1000000007
#define N 200010
int m, a, b;
int d[N];
int s[N];

int gcd(int a, int b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}

int main() {
	cin >> m >> a >> b;
	m++;
	for (int i = 1; i < a+a; i ++) d[i] = INF;
	set<PII> q;
	q.insert(mp(0, 0));
	while (!q.empty()) {
		int x = q.begin()->se;
		q.erase(q.begin());
		if (x >= b) {
			if (d[x-b] > d[x]) {
				q.erase(mp(d[x-b], x-b));
				d[x-b] = d[x];
				q.insert(mp(d[x-b], x-b));
			}
		}
		if (x+a < a+b) {
			if (d[x+a] > max(d[x], x+a)) {
				q.erase(mp(d[x+a], x+a));
				d[x+a] = max(d[x], x+a);
				q.insert(mp(d[x+a], x+a));
			}
		}
	}
	for (int i = 0; i < a+a; i ++)
		if (d[i] < INF) s[d[i]] ++;
	for (int i = 0; i < a+a; i ++) s[i+1] += s[i];
	ll S = 0;
	for (int i = 0; i < min(m, a+a); i ++) S += s[i];
	if (a+a < m) {
		int g = gcd(a, b);
		int le = a+a, ri = m-m%g;
		S += (ll)(ri-le) * (le/g + ri/g +1)/2;
		S += m%g * (m/g+1);
	}
	cout << S << endl;
	return 0;
}

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")

//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)
//logb(n)=loga(n)/loga(b)

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

//(a+b)^n=sum of C(n,i)*a^i*b^(n-i) 0<=i<=n
//(a-b)^n=sum of C(n,i)*a^i*b^(n-i) for even i-for odd i

#define gainf pop_front
#define len(x) (int)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0
// a^b=(a+b)-2(a&b)

typedef double db;
typedef long long ll;

//sum of squares n*(n+1)*(2n+1)/6
//sum of cubes [n*(n+1)/2]^2
//sum of squares for odds n*(4*n*n-1)/3
//sum of cubes for odds n*n*(2*n*n-1)

const ll ary=5e5+5;
const int mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
ll m,a,b;
vector<ll> d(ary,inf);
set< pair<ll,int> > q;
ll ans;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>m>>a>>b;
	q.insert({0,0});
	d[0]=0;
	while(len(q)){
		int v=q.begin()->s;
		q.erase(q.begin());
		if(v+a<=ary-5&&d[v+a]>max(d[v],v+a)){
			q.erase({d[v+a],v+a});
			d[v+a]=max(d[v],v+a);
			q.insert({d[v+a],v+a});
		}
		if(v-b>=0&&d[v-b]>max(d[v],v-b)){
			q.erase({d[v-b],v-b});
			d[v-b]=max(d[v],v-b);
			q.insert({d[v-b],v-b});
		}
	}
	for(int i=0;i<=min(ary-5,m);i++){
		ans+=max(0ll,m-d[i]+1);
	}
	if(m>ary-5){
		ll g=__gcd(a,b);
		ll l=ary-4,r=m;
		if(l%g){
			l+=(g-(l%g));
		}
		r-=(r%g);
		if(r>=l){
			ll c=(r-l)/g+1;
			ans+=g*c*(c-1)/2+c;
		}
	}
	cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 100005;
struct Edge { int to, next; } edge[MAXN];
int head[MAXN], que[MAXN], dis[MAXN], f[MAXN], g[MAXN], n, a, b, tot;
void addedge(int u, int v) {
	edge[++tot] = (Edge) { v, head[u] };
	head[u] = tot;
}
ll sum(int x) {
	int t = x / a;
	return (ll)(1 + t) * t / 2 * a + (ll)(x - t * a) * (t + 1);
}
int main() {
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < a; i++) addedge((i + b) % a, i);
	memset(dis, -1, sizeof(dis));
	int he = 0, ta = 0;
	dis[que[ta++] = 0] = 0;
	while (he < ta) {
		int u = que[he++];
		for (int i = head[u]; i; i = edge[i].next) {
			int v = edge[i].to;
			if (dis[v] < 0) dis[que[ta++] = v] = dis[u] + 1;
		}
	}
	for (int i = 1; i < b; i++)
		g[i] = max(g[i - 1], a * (i - 1) % b + a);
	ll res = 0;
	for (int i = 0; i < a; i++) if (dis[i] >= 0) {
		int d = g[min((dis[i] * b + a - 1) / a, b - 1)];
		res += sum(n - i + 1) - sum(min(d, n + 1) - i);
	}
	printf("%lld\n", res);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e5+5;
ll cnt[N],sum[N];
bool vis[N];
ll gcd(ll a,ll b){
	if(a%b==0)
		return b;
	return gcd(b,a%b);
}
priority_queue<pii,vector<pii>,greater<pii>>q;
int main()
{
	ll m,a,b;
	cin>>m>>a>>b;
	q.push(pii(0,0));
	ll mx=min(a+b-1,m);
	while(!q.empty()){
		ll pre=q.top().fi;
		ll now=q.top().se;
		q.pop();
		cnt[pre]++;
		if(now-b>0&&!vis[now-b]){
			q.push(pii(pre,now-b));
			vis[now-b]=true;
		}
		if(now+a<=mx&&!vis[now+a]){
			q.push(pii(max(now+a,pre),now+a));
			vis[now+a]=true;
		}
	}
//	rep(i,0,mx+1)
//		de(cnt[i])
	sum[0]=cnt[0];
	ll ans=sum[0];
	rep(i,1,mx+1){
		sum[i]=sum[i-1]+cnt[i];
		ans+=sum[i];
	}
//	de(ans)
	if(mx<m){
		mx++;
		ll g=gcd(a,b);
	/*	de(g)
		dd(m)
		de(mx)*/
		if(g==1){
			ans+=(m-mx+1)*(m+mx+2)/2;
		}
		else{
			while(mx<=m&&mx%g!=1){
				ans+=mx/g;
				mx++;
			}
			 while(mx<=m&&(m%g)){
			 	ans+=m/g;
			 	m--;
			 }
		/*	 de(ans)
			 dd(m)
			 de(mx)*/
			 ll l=mx/g,r=m/g;
			 ans+=(r-l+1)*(r+l+2)/2*g;
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
long long gcd(long long a,long long b)
{
	if (a%b==0) return b;
	return gcd(b,a%b);
}
long long add(long long k,long long x)
{
	long long m=(k+1)/x;
	return (k+1)*m-(x*m*(m+1)/2);
}
int main()
{
	//freopen("b.in","r",stdin);
	//freopen("b.out","w",stdout);
	long long n,a,b;
	scanf("%lld %lld %lld",&n,&a,&b);
	long long x=gcd(a,b);
	long long ma1=0;
	long long ma=max(2*a,2*b);
	long long z=ma;
	long long si=0;
	long long ans=0;
	if (a==b)
	{
		printf("%lld",add(n,a));
		return 0;
	}

	do
	{
		if (si>=b)
		{
			int t=si/b;
			si-=t*b;
			if (si==0) t--;
			ans+=t*(z-ma1+1);
			}
		else
		if (si+a<=ma1)
		{
			int t=(ma1-si)/a;
			si+=t*a;
			ans+=t*(z-ma1+1);
		}
		else
		{
			int t=(b-si+a-1)/a;
			if (si+t*a>n)
			{
				for (int si=1;si<=n;si+=a)
				{
					ans+=(z-si+1);
				}
				break;
			}
			else
			{
				si+=a*t;
				ma1=si;
				ans+=t*(z-si+1);
			}
		}
//		printf("%d ",ans);
//		printf("%d \n",si);
		if (si==0||n<ma1) break;
	}
	while (1);
	ans=0;si=0; z=min(n,ma1); ma=ma1; ma1=0;

//	printf("%d",ma);
	do
	{
		if (si>=b)
		{
			int t=si/b;
			si-=t*b;
			if (si==0) t--;
			ans+=t*(z-ma1+1);
			}
		else
		if (si+a<=ma1)
		{
			int t=(ma1-si)/a;
			si+=t*a;
			ans+=t*(z-ma1+1);
		}
		else
		{
			int t=(b-si+a-1)/a;
			if (si+t*a>n)
			{
				for (int si=1;si<=n;si+=a)
				{
					ans+=(z-si+1);
				}
				break;
			}
			else
			{

				ans+=(z-si+1)*t-(t*(t+1)/2)*a;
				si+=a*t;
				ma1=si;
			}
		}
//		printf("%d ",ans);
//		printf("%d \n",si);
		if (si==0||n<ma1) break;
	}
	while (1);
	ans+=n+1;
	if (n>ma) ans+=add(n,x)-add(ma,x);
	printf("%lld",ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll m, a, b;
  cin >> m >> a >> b;

  if (m < a) {
    cout << m + 1 << '\n';
    return 0;
  }

  ll total = a;
  ll g = __gcd(a, b);

  ll cut = a + a % b;

  for (int i = a; i <= min(m, cut - 1); ++i) {
    total += 2;
    if (b >= a) {
      continue;
    }
    total += a / b;
  }

  if (m < cut) {
    cout << total << '\n';
    return 0;
  }

  // fuck me
  ll start = cut / g;
  ll end = m / g;

  // sum start + 1 to end - 1
  ll i = cut;
  while (i / g == start) {
    total += 1 + i / g;
    ++i;
  }

  if (start != end) {
    i = m;
    while (i / g == end) {
      total += 1 + i / g;
      --i;
    }
  }

  if (end - start > 1) {
    total += (start + end + 2) * (end - start - 1) / 2 * g;
  }

  cout << total << '\n';

  return 0;
}

#pragma region Include/Defines
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <queue>
#include <time.h>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef vector<pii> vpii;
typedef vector <pll> vpll;
typedef long double ld;
#define all(a) std::begin(a), std::end(a)

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

template<typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); }
template<typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); }

#ifdef _DEBUG
#define epr(...) fprintf(stderr,__VA_ARGS__)
#else
#define epr(...)
#endif
#pragma endregion

const int MAX = 4e5 + 10;
int m, a, b, gd;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

void clear() {
}

void read() {
}

int f(int n) {
	set<int> used = { 0 };
	set<int> q = { 0 };
	while (!q.empty()) {
		auto x = *q.begin();
		q.erase(q.begin());
		if (!used.count(x + a) && x + a <= n)  used.insert(x + a), q.insert(x + a);
		if (!used.count(x - b) && x - b >= 0)  used.insert(x - b), q.insert(x - b);
	}
	cerr << n << ":" << used.size() - 1 << endl;
	return used.size();
}

lli solve1() {
	lli s = 0;
	for (int i = 0; i <= m; i++) s += f(i);
	return s;
}

lli solve2() {
	lli res = 1;
	int lim = a + b, gd = gcd(a, b);
	set<int> used = { 0 };
	for (int n = 1; n < min(m + 1, lim); n++) {
		if (used.count(n - a)) {
			set<int> q = { n };
			used.insert(n);
			while (!q.empty()) {
				auto x = *q.begin();
				q.erase(q.begin());
				if (!used.count(x + a) && x + a <= n)  used.insert(x + a), q.insert(x + a);
				if (!used.count(x - b) && x - b >= 0)  used.insert(x - b), q.insert(x - b);
			}
		}
		res += used.size();
	}
	if (lim < m) {
		int d = m - lim + 1;
		int ng = d / gd;
		int zm = lim + ng * gd;

		// prog
		if (lim < zm) {
			int a1 = lim / gd;
			int an = (zm - 1) / gd;
			lli s = 1ll * ng * (a1 + an) / 2 * gd;
			res += s;
		}

		if (zm <= m)
			res += (m - zm + 1) * (zm / gd);
	}
	return res;
}

void solve() {
	//lli res1 = solve1();
	lli res2 = solve2();
	//assert(res1 == res2);
	printf("%lld\n", res2);
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d%d%d", &m, &a, &b) == 3) {
		clear();
		read();
		gd = gcd(a, b);
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long int

#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define _cin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()

#define INF 2147483647
#define MAXN 2000004
#define endl "\n"

ll mod = 1000000007;

ll vis[MAXN];

ll getSum(ll a, ll b)
{
    ll x, y;
    a--;
    x = (a * (a + 1)) / 2;
    y = (b * (b + 1)) / 2;
    return y - x;
}

ll getNum(ll n, ll hcf)
{
    return 1 + (n / hcf);
}

int main()
{
    _cin;
    ll m, a, b, tmp, sum, left, rem, comp;
    cin >> m >> a >> b;
    ll num = 1, last = 0, ans = 1, tot = 1, flag = 0, curr, hcf = __gcd(a, b), res;
    vis[0] = 1;
    while(num <= 2 * (a + b) && num <= m){
        res = getNum(num - 1, hcf);
        if(num >= (a + b) && res == tot){
            break;
        }
        //cout << "ans = " << ans << " num = " << num << " tot = " << tot << " curr = " << curr << " last = " << last << " flag = " << flag << endl;
        curr = tot;
        while(1){
            tmp = curr;
            while(last - b > 0 && vis[last - b] == 0){
                last -= b;
                vis[last] = 1;
                curr++;
            }
            while(last + a <= num && vis[last + a] == 0){
                last += a;
                vis[last] = 1;
                curr++;
            }
            if(tmp == curr) break;
        }
        tot = curr;
        ans += tot;
        num++;
    }
    if(num > m){
        cout << ans << endl;
    }
    else{
        num -= 2;
        ans -= tot;
        left = m - num;
        rem = left % hcf;
        comp = left / hcf;
        sum = getSum(tot, tot + comp - 1);
        sum = sum * hcf;
        ans += sum;
        tot += comp;
        ans += tot * rem;
        cout << ans << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define eps 1e-6
#define inf (ll)1e18
#define mod 1000000007

using namespace std;

typedef unsigned long long ll;
typedef long double ld;

long long a, b;
ll m, Viz[1000005], SP[1000005], SSP[1000005];
set<pair<long long, long long> , less<> > S;

ll gcd(ll a, ll b)
{
    while (b)
    {
        ll r= a%b;
        a=b;
        b=r;
    }
    return a;
}

int main()
{
    cin>>m>>a>>b;
    ll lim = min((ll)1e6, m);
    for (ll i=0; i<=1e6; i++)
        Viz[i]=inf;
    S.insert({0, 0});
    Viz[0]=0;
    while (!S.empty()) {
        long long x = S.begin()->first;
        long long  dist = S.begin()->second;
        S.erase(S.begin());
        if (x - b >= 0 && Viz[x - b] > dist) {
            S.insert({x - b, dist});
            Viz[x - b] = dist;
        }
        if (x + a <= lim && Viz[x + a] > dist) {
            S.insert({x + a, max(dist, x+a)});
            Viz[x + a] = max(x+a, dist);
        }
    }

    for (ll i=0; i<=lim; i++)
        if (Viz[i]!=inf)
            SP[Viz[i]]++;

    for (ll i=1; i<=lim; i++)
        SP[i]+=SP[i-1];
    for (ll i=0; i<=lim; i++)
        SSP[i]+=SSP[i-1]+SP[i];

    if (m<=1e6)
    {
        cout<<SSP[m]<<endl;
    }
    else
    {
        ll g = gcd(a, b);
        ll last = m;
        m/=g;
        ll sum1 = (m*(m+1)/2)*g;
        ll sum2 = (last%g+1)*(m+1);
        cout<<sum1+sum2<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
const ll INF=1e16;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll m,a,b;
    cin>>m>>a>>b;
    ll g=__gcd(a,b);
    ll ans=0;
    v ma(a+b+1,-1);
    ll current=a;
    ma[0]=0;
    ma[a]=a;
    ll maxi=a;
    while (current!=0)
    {
        if (current<b)
        {
            current+=a;
        }
        else
            current-=b;
        if (current==0)
            break;
        maxi=max(maxi,current);
        ma[current]=maxi;
    }
    ll i;
    for (i=0; i<(a+b); i=i+g)
    {
        if (m>=ma[i] && m>=i)
            ans=ans+(m-ma[i]+1);
    }
    if (m>=a+b)
    {
        ll t1=m-m%g;
        ll t2=a+b;
        ll a=1;
        ll num=1+(t1-t2)/g;
        ll sum=(num*(2*a+(num-1)*g))/2;
        ans+=sum;
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5+10;
int f[maxn*10];
int minPos[maxn * 10];
int dp[maxn * 10];

void dfs(int u, int a,int b) {
	priority_queue<int> q;
	q.push(0);
	f[0] = true;
	minPos[0] = 0;
	while (!q.empty()) {
		int u = -q.top();
		q.pop();
		if (u + a < maxn * 10 && !f[u+a]) {
			int v = u + a;
			q.push(-v);
			minPos[v] = max(v, minPos[u]);
			f[v] = true;
		}
		//if (u == 7) cerr << "xxx " << f[u-a] << endl;
		if (u - b >= 0 && !f[u-b]) {
			int v = u - b;
			q.push(-v);
			minPos[v] = minPos[u];
			f[v] = true;
		}
		//q.pop();
	}
}

long long get(int l,int r, int t) {
	while (l%t) l++;
	if (l>r) return 0;
	return (r - l) / t + 1;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m, a, b;
	cin >> m >> a >> b;
	int t = max(a,b);
	memset(minPos, -1,sizeof(minPos));
	dfs(0, a, b);
	//cerr << "asdf" << endl;
	priority_queue<int> q;
	//for(int i=0;i<20;i++) cerr << i <<" " <<f[i] <<" " <<minPos[i] << endl;
	for(int i=0;i<maxn * 10;i++) {
		if (i) dp[i] = dp[i-1];
		if (f[i]) {
			q.push(-minPos[i]);
		}

		while (q.size() && -q.top() <=i) {
			dp[i]++;
			q.pop();
		}
	}
	//for(int i=0;i<10;i++) cout <<"ttt " << i<<" "<< dp[i] <<endl;
	long long res = 0;

	if (m > maxn * 4) {
		for(int i=0;i<maxn * 4;i++) {
			res += dp[i];
		}
		int t = __gcd(a,b);
		res += 1ll * dp[maxn * 4 - 1] * (m - maxn * 4 + 1);
		long long tmp = get(maxn * 4, m, t);
		res += (tmp * (tmp + 1)) / 2 * t;
		res -= (maxn * 4 + tmp * t - m);
	} else {
		for(int i=0;i<=m;i++) {
			res += dp[i];
		}
	}
	cout << res;
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,a,b) for (int i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mitte (lewy+prawy)/2
#define debug printf
using namespace std;
typedef long long ll;
typedef long double ld;
ll a, b, m;
vector <ll> dist;
vector <bool> resz;

ll ary (ll start, ll roz = a)
{
	ll ile = start/roz + 1LL;
	return ((start + start % roz) * ile)/2LL;
}

int main ()
{
	scanf ("%lld %lld %lld", &m, &a, &b);
	resz.resize(a, false);
	ll r=0;
	while (!resz[r])
	{
		resz[r] = true;
		if (r<b) r+=((b-r+a-1LL)/a) * a;
		r-=b;
	}
	ll G = ((b+a)/a) * a + 2LL * a;

	ll res=0;
	ll p;
	rep(i,0,a) if (resz[r])
	{
		p=G+ll(i);
		if (p<=m)
		{
			res += ary(m - p + 1LL);
		}
	}

	//dla reszty dijksta
	vector <ll> dist(G+b+1, 1e9);
	priority_queue <pair <int, int> > kol;
	kol.push(mp(0, 0));
	while (!kol.empty())
	{
		pair <int, int> q = kol.top();
		kol.pop();
		if (dist[q.se]<1e8) continue;
		dist[q.se] = -q.fi;
		if (q.se>b) kol.push(mp(q.fi, q.se-b));
		if (q.se+a <=G+b) kol.push(mp(min(q.fi, -q.se-(int)a), q.se+a));
	}

	rep(i,0,G)
	{
		//debug ("%d: %lld\n", i, dist[i]);
		if (dist[i]<=m) res+=m - dist[i]+1LL;
	}
	printf ("%lld\n", res);
}

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <algorithm>
using namespace std;
const int N=100005,M=1000000007;
int n,i,a,b,f[500005],s,mx;
long long ans;
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main(){
	scanf("%d %d %d",&n,&a,&b);
	int g=gcd(a,b);
	n/=g;
	a/=g;
	b/=g;
	i=a;
	mx=a;
	while(1)
	{
		while(i>=b)
		{
			i-=b;
			f[i]=mx;
		}
		mx=max(mx,i+a);
		if(i==0)
			break;
		i+=a;
	}
	f[0]=0;
	for(i=a;i<mx&&i<=n;i++)
		f[i]=max(i,f[i-a]);
	for(i=0;i<mx&&i<=n;i++)
		if(f[i]<=n)
			ans+=n-f[i]+1;
	if(n>=mx)
		cout<<ans+1ll*(n-mx+1)*(n-mx+2)/2;
	else
		cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll m, a, b, d, x=0;
ll repeat[100100];
ll sum(ll n) { return n*(n+1)/2; }
ll get(ll x, ll mod)
{
    ll ans=0;
    ll nxt= ((x-mod)/a+1) *a+mod;
    nxt=min(nxt, m);
    ans+=nxt-x;
    ll k=(m-mod)/a;
    if (k<1) return ans;
    ans+=a*(sum(k) - 1) + (m-k*a-mod+1) * (k+1);
    return ans;
}
int main()
{
    cin>>m>>a>>b;
    if (m<a) { cout<<m+1; return 0; }
    ll initial=0;
    memset(repeat, -1, sizeof repeat);
    while (repeat[initial%a]==-1)
    {
        repeat[initial%a]=x;
        while (initial<b && initial+a<=m) initial+=a;
        x=max(x, initial);
        initial-=b;
    }
    ll rez=0;
    for(int i=0; i<a; ++i) if (repeat[i]!=-1) rez+=get(repeat[i], i);
    cout<<rez;
}

#include <bits/stdc++.h>

#define _USE_MATH_DEFINES
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define remax(x, y) (x) = max((x), (y))
#define remin(x, y) (x) = min((x), (y))

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll sum(ll a) {
    return a * (a + 1) / 2;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    ll m, a, b;
    cin >> m >> a >> b;

    int seen = 0;
    vector<pll> start(a, {-1, -1});

    priority_queue<ll, vector<ll>, greater<ll>> pq;
    pq.push(0);

    ll x = 0;
    ll d = gcd(a, b);
    while (seen < a / d) {
        ll y = pq.top();
        pq.pop();

        remax(x, y);
        for (; y >= 0; y -= b) {
            if (start[y % a].F == -1) {
                start[y % a] = {y, x};
                seen++;
            }
            pq.push(y + a);
        }
    }

    ll ans = 0;
    forn(i, a) {
        if (start[i].S > m)
            continue;

        ll L = start[i].S - start[i].F;
        ll R = m - start[i].F;

        ans += R - L + 1;
        ans += a * (sum(R / a) - sum(L / a - 1));
        ans -= (L / a) * (L % a);
        ans -= (R / a) * (a - 1 - R % a);
    }

    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
int m, a, b;

int gcd (int a, int b) {
	return b ? gcd(b, a % b) : a;
}

const int maxn = 200010;
int dp[maxn], f[maxn];
long long ans;
int now;

void solve (int x, int top) {
	if (x - b >= 0 && !dp[x - b]) {
		now ++;
		dp[x - b] = 1;
		solve(x - b, top);
	}
	if (x + a <= top && !dp[x + a]) {
		now ++;
		dp[x + a] = 1;
		solve(x + a, top);
	}
}

int main() {
	cin >> m >> a >> b;
	int d = gcd(a, b);
	int n = m / d;
	a /= d;
	b /= d;
	//cout << d << endl;
	dp[0] = now = 1;
	f[0] = 1;
	for (int i = 1; i <= 200000; i ++) {
		if (i >= a) dp[i] = dp[i - a];
		if (dp[i]) {
			now ++;
			solve(i, i);
		}
		f[i] = now;
		// cout << f[i] << endl;
	}
	assert(f[200000] == 200001);
	for (int i = n * d; i <= m; i ++) {
		if (n <= 200000) ans += f[n];
		else ans += n + 1;
	}
	//cout << ans << endl;
	int k;
	for (int i = 0; i * d < m && (i + 1) * d - 1 <= m && i <= 200000; i ++) {
		ans += 1ll * d * f[i];
		k = i;
	}
	if (k == 200000) {
		ans += 1ll * (200002ll + n) * (n - 200001ll) / 2ll * d;
		// for (int i = k + 1; i < n; i ++)
		// 	ans += 1ll * d * (i + 1);
	}
	cout << ans << endl;
}

// 1 1 2 2 3 3 4

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

// #undef DEBUG
// #define DEBUG
// DEBUG {{{
#include <array>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>
template < int n, class... T >
typename std::enable_if< (n >= sizeof...(T)) >::type __output_tuple(
    std::ostream &, std::tuple< T... > const &) {}
template < int n, class... T >
typename std::enable_if< (n < sizeof...(T)) >::type __output_tuple(
    std::ostream &os, std::tuple< T... > const &t) {
  os << (n == 0 ? "" : ", ") << std::get< n >(t);
  __output_tuple< n + 1 >(os, t);
}
template < class... T >
std::ostream &operator<<(std::ostream &os, std::tuple< T... > const &t) {
  os << "(";
  __output_tuple< 0 >(os, t);
  os << ")";
  return os;
}
template < class T, class U >
std::ostream &operator<<(std::ostream &os, std::pair< T, U > const &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template < class T >
std::ostream &operator<<(std::ostream &os, const std::stack< T > &a) {
  os << "{";
  for(auto tmp = a; tmp.size(); tmp.pop())
    os << (a.size() == tmp.size() ? "" : ", ") << tmp.top();
  os << "}";
  return os;
}
template < class T, class Container, class Compare >
std::ostream &operator<<(std::ostream &os,
    std::priority_queue< T, Container, Compare > a) {
  os << "{ (top) ";
  while(a.size()) os << a.top() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
template < class T, class Container >
std::ostream &operator<<(std::ostream &os, std::queue< T, Container > a) {
  os << "{ ";
  while(a.size()) os << a.front() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
#ifdef DEBUG
#if !defined(DEBUG_OUT)
// #define DEBUG_OUT std::cerr
#endif
#define dump(...)                                                                \
  [&]() {                                                                        \
    auto __debug_tap = std::make_tuple(__VA_ARGS__);                             \
    DEBUG_OUT << "[" << __LINE__ << "] " << #__VA_ARGS__ << " = " << __debug_tap \
    << std::endl;                                                      \
  }()
template < class T >
inline void dump2D(T &d, size_t sizey, size_t sizex) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << "\t";
    for(size_t j = 0; j < sizex; j++)
      DEBUG_OUT << d[i][j] << (j + 1 == sizex ? "" : "\t");
    DEBUG_OUT << std::endl;
  }
}
template < class T >
inline void dump1D(T &d, size_t sizey) {
  for(size_t i = 0; i < sizey; i++) {
    DEBUG_OUT << d[i] << (i + 1 == sizey ? "" : " ");
  }
  DEBUG_OUT << std::endl;
}
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        os << "{";
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : ", ") << *ite;
        os << "}";
        return os;
      }
#else
#define dump(...) (42)
#define dump2D(...) (42)
#define dump1D(...) (42)
template <
class T, class = typename std::iterator_traits< decltype(begin(T())) >::value_type,
      class = typename std::enable_if< !std::is_same< T, std::string >::value >::type >
      std::ostream &operator<<(std::ostream &os, const T &a) {
        for(auto ite = begin(a); ite != end(a); ++ite)
          os << (ite == begin(a) ? "" : " ") << *ite;
        return os;
      }
#endif
// }}}

/// --- math {{{ ///
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d;
  return b == 0 ? (x = a < 0 ? -1 : 1, y = 0, a < 0 ? -a : a)
    : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
}
ll modinv(ll a, ll mod) {
  ll x, y;
  extgcd(a, mod, x, y);
  if(x < 0) x += mod;
  return x;
}
ll modpow(ll a, ll b, ll mod) {
  ll r = 1;
  a %= mod;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
/// }}}--- ///

// LazySegmentTree( size [, initial] )
// LazySegmentTree( <data> )
/// --- LazySegmentTree {{{ ///
#include <cassert>
#include <initializer_list>
#include <iostream>
#include <vector>
template < class M_act >
struct LazySegmentTree {
public:
  using Monoid = typename M_act::Monoid;
  using X = typename Monoid::T;
  using M = typename M_act::M;

private:
  size_t n;
  int h;
  vector< X > data;
  vector< M > lazy;
  vector< size_t > nodeLength;
  // call before use data[i]
  void eval(size_t i) {
    if(lazy[i] == M_act::identity()) return;
    data[i] = M_act::actInto(lazy[i], nodeLength[i], data[i]);
    if(i < n) {
      lazy[i * 2] = M_act::op(lazy[i], lazy[i * 2]);
      lazy[i * 2 + 1] = M_act::op(lazy[i], lazy[i * 2 + 1]);
    }
    lazy[i] = M_act::identity();
  }
  // call before use seg[i] = data[i + n]
  void evalDown(size_t i) {
    i += n;
    for(int j = h - 1; j >= 0; j--) eval(i >> j);
  }
  // call after touch seg[i] = data[i + n]
  void propUp(size_t i) {
    i += n;
    while(i >>= 1)
      eval(i * 2), eval(i * 2 + 1), data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
  }

public:
  LazySegmentTree() : n(0) {}
  LazySegmentTree(size_t n, X initial = Monoid::identity()) : n(n) {
    if(n > 0) {
      h = 1;
      while(1u << h < n) h++;
      data.resize(2 * n, initial);
      lazy.resize(2 * n, M_act::identity());
      nodeLength.resize(2 * n, 1);
      for(size_t i = n - 1; i > 0; i--) // fill from deep
        data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]),
          nodeLength[i] = nodeLength[i * 2] + nodeLength[i * 2 + 1];
    }
  }
  template < class InputIter, class = typename iterator_traits< InputIter >::value_type >
    LazySegmentTree(InputIter first, InputIter last)
    : LazySegmentTree(distance(first, last)) {
      if(n > 0) {
        copy(first, last, begin(data) + n);
        for(size_t i = n - 1; i > 0; i--) // fill from deep
          data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
      }
    }
  LazySegmentTree(vector< X > v) : LazySegmentTree(v.begin(), v.end()) {}
  LazySegmentTree(initializer_list< X > v) : LazySegmentTree(v.begin(), v.end()) {}
  void act(int l, int r, const M &m) {
    if(l < 0) l = 0;
    if(l >= r) return;
    if(r > (int) n) r = n;
    evalDown(l);
    evalDown(r - 1);
    int tl = l, tr = r;
    for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) eval(l), lazy[l] = m, eval(l), l++;
      if(r & 1) --r, eval(r), lazy[r] = m, eval(r);
    }
    propUp(tl);
    propUp(tr - 1);
  }
  void set(size_t i, const X &x) {
    assert(i < n);
    evalDown(i);
    data[i + n] = x;
    propUp(i);
  }
  X get(size_t i) {
    assert(i < n);
    evalDown(i);
    return data[i + n];
  }
  X fold(int l, int r) {
    if(l < 0) l = 0;
    if(l >= r) return Monoid::identity();
    if(r > (int) n) r = n;
    evalDown(l);
    evalDown(r - 1);
    X tmpL = Monoid::identity(), tmpR = Monoid::identity();
    for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) eval(l), tmpL = Monoid::op(tmpL, data[l]), l++;
      if(r & 1) --r, eval(r), tmpR = Monoid::op(data[r], tmpR);
    }
    return Monoid::op(tmpL, tmpR);
  }
  int size() { return n; }
  inline void dum(int r = -1) {
#ifdef DEBUG
    if(r < 0) r = n;
    DEBUG_OUT << "{";
    for(int i = 0; i < min(r, (int) n); i++) DEBUG_OUT << (i ? ", " : "") << get(i);
    DEBUG_OUT << "}" << endl;
#endif
  }
};

/// }}}--- ///

/// --- Monoid examples {{{ ///
constexpr long long inf_monoid = 1e18 + 100;
#include <algorithm>
struct Nothing {
  using T = char;
  using Monoid = Nothing;
  using M = T;
  static constexpr T op(const T &, const T &) { return T(); }
  static constexpr T identity() { return T(); }
  template < class X >
    static constexpr X actInto(const M &, long long, const X &x) {
      return x;
    }
};

template < class U = long long >
struct RangeMin {
  using T = U;
  static T op(const T &a, const T &b) { return std::min< T >(a, b); }
  static constexpr T identity() { return T(inf_monoid); }
};

template < class U = long long >
struct RangeMax {
  using T = U;
  static T op(const T &a, const T &b) { return std::max< T >(a, b); }
  static constexpr T identity() { return T(-inf_monoid); }
};

template < class U = long long >
struct RangeSum {
  using T = U;
  static T op(const T &a, const T &b) { return a + b; }
  static constexpr T identity() { return T(0); }
};

template < class U >
struct RangeProd {
  using T = U;
  static T op(const T &a, const T &b) { return a * b; }
  static constexpr T identity() { return T(1); }
};

template < class U = long long >
struct RangeOr {
  using T = U;
  static T op(const T &a, const T &b) { return a | b; }
  static constexpr T identity() { return T(0); }
};

#include <bitset>

template < class U = long long >
struct RangeAnd {
  using T = U;
  static T op(const T &a, const T &b) { return a & b; }
  static constexpr T identity() { return T(-1); }
};

template < size_t N >
struct RangeAnd< std::bitset< N > > {
  using T = std::bitset< N >;
  static T op(const T &a, const T &b) { return a & b; }
  static constexpr T identity() { return std::bitset< N >().set(); }
};

/// }}}--- ///

/// --- M_act examples {{{ ///
template < class U = long long, class V = U >
struct RangeMinAdd {
  using X = U;
  using M = V;
  using Monoid = RangeMin< U >;
  static M op(const M &a, const M &b) { return a + b; }
  static constexpr M identity() { return 0; }
  static X actInto(const M &m, long long, const X &x) { return m + x; }
};

template < class U = long long, class V = U >
struct RangeMaxAdd {
  using X = U;
  using M = V;
  using Monoid = RangeMax< U >;
  static M op(const M &a, const M &b) { return a + b; }
  static constexpr M identity() { return 0; }
  static X actInto(const M &m, long long, const X &x) { return m + x; }
};

template < class U = long long, class V = U >
struct RangeMinSet {
  using M = U;
  using Monoid = RangeMin< U >;
  using X = typename Monoid::T;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return M(-inf_monoid); }
  static X actInto(const M &m, long long, const X &x) { return m == identity() ? x : m; }
};

template < class U = long long, class V = U >
struct RangeMaxSet {
  using M = U;
  using Monoid = RangeMax< U >;
  using X = typename Monoid::T;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return M(-inf_monoid); }
  static X actInto(const M &m, long long, const X &x) { return m == identity() ? x : m; }
};

template < class U = long long, class V = U >
struct RangeSumAdd {
  using X = U;
  using M = V;
  using Monoid = RangeSum< U >;
  static M op(const M &a, const M &b) { return a + b; }
  static constexpr M identity() { return 0; }
  static X actInto(const M &m, long long n, const X &x) { return m * n + x; }
};

template < class U = long long, class V = U >
struct RangeSumSet {
  using X = U;
  using M = V;
  using Monoid = RangeSum< U >;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return M(-inf_monoid); }
  static X actInto(const M &m, long long n, const X &x) {
    return m == identity() ? x : m * n;
  }
};

template < class U, class V = U >
struct RangeProdMul {
  using X = U;
  using M = V;
  using Monoid = RangeProd< U >;
  static M mpow(M a, long long b) {
    X r(1);
    while(b) {
      if(b & 1) r = r * a;
      a = a * a;
      b >>= 1;
    }
    return r;
  }
  static M op(const M &a, const M &b) { return a * b; }
  static constexpr M identity() { return M(1); }
  static X actInto(const M &m, long long n, const X &x) { return x * mpow(m, n); }
};

template < class U, class V = U >
struct RangeProdSet {
  using X = U;
  using M = V;
  using Monoid = RangeProd< U >;
  static M op(const M &a, const M &) { return a; }
  static constexpr M identity() { return V::unused; }
  static X actInto(const M &m, long long n, const X &) {
    if(m == identity()) return;
    return RangeProdMul< U, V >::mpow(m, n);
  }
};

template < class U = long long, class V = U >
struct RangeOr2 {
  using X = U;
  using M = V;
  using Monoid = RangeOr< U >;
  static M op(const M &a, const M &b) { return a | b; }
  static constexpr M identity() { return M(0); }
  static X actInto(const M &m, long long, const X &x) { return m | x; }
};

template < class U = long long, class V = U >
struct RangeAnd2 {
  using X = U;
  using M = V;
  using Monoid = RangeAnd< U >;
  static M op(const M &a, const M &b) { return a & b; }
  static constexpr M identity() { return M(-1); }
  static X actInto(const M &m, long long, const X &x) { return m & x; }
};

template < class U, size_t N >
struct RangeAnd2< U, std::bitset< N > > {
  using X = U;
  using M = std::bitset< N >;
  using Monoid = RangeAnd< U >;
  static M op(const M &a, const M &b) { return a & b; }
  static constexpr M identity() { return std::bitset< N >().set(); }
  static X actInto(const M &m, long long, const X &x) { return m & x; }
};
/// }}}--- ///

using Seg = LazySegmentTree< RangeSumAdd<> >;

ll rangesum(ll a, ll b) {
  // ll sum = 0;
  // for(ll i = a; i <= b; i++) sum += i;
  // return sum;
  return (b - a + 1) * (b - a + 2) / 2 + (b - a + 1) * (a - 1);
}

int m, a, b;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> m >> a >> b;
  vector<int> v(a, -1);
  v[0] = 0;

  int now = 0;
  while(true) {
    int nxt = ((now - b) % a + a) % a;
    if(nxt == 0) break;
    int h = now + max(b - now, 0) / a * a;
    while(h < b) h += a;
    v[nxt] = max(v[now], h);
    now = nxt;
  }

  vector<pair<int, int>> w;
  for(int i = 0; i < a; i++) w.emplace_back(v[i], i);
  w.emplace_back(m + 1, 0);
  sort(begin(w), end(w));

  ll L = 0;
  ll ans = 0;

  Seg seg(a);

  auto calc = [&](ll L, ll R, ll g, ll num) {
    return (R - L + 1) * (g - 1) * num + seg.fold(L % a, R % a + 1);
  };

  // dump(rangesum(0, 10));
  // dump(rangesum(2, 10));
  // dump(rangesum(7, 10));

  for(int i = 0; i <= a; i++) {
    if(w[i].first == -1) continue;
    ll R = w[i].first - 1;
    R = min<ll>(R, m);
    // dump(seg.fold(0, 1));
    // dump(L, R);
    if(L <= R) {
      // dump(i);
      ll lg = L / a + 1;
      ll rg = R / a + 1;
      if(lg == rg) {
        ans += calc(L, R, lg, i);
      } else {
        if(lg + 1 <= rg - 1) ans += rangesum(lg + 1 - 1, rg - 1 - 1) * a * i + seg.fold(0, a) * (rg - lg - 2 + 1);
        ans += calc(L, lg * a - 1, lg, i);
        ans += calc(rg * a - a, R, rg, i);
      }
      L = R + 1;
    }
    if(L == m + 1) break;
    seg.act(w[i].second, a, 1);
  }

  cout << ans << endl;

  return 0;
}

#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#define R register
#define ll long long
using namespace std;
const int N = 210000;

int n, a, b, f[N];
ll ans;
queue<int> que;

template <class T> inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch))
		w = (ch == '-'), ch = getchar();
	while (isdigit(ch))
		x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int getGcd(int a, int b) {
	return b ? getGcd(b, a % b) : a;
}

inline ll getSum(int n, int d) {
	ll k = n / d;
	return k * (k + 1) / 2 + (k + 1) * (n % d);
}

int main() {
	read(n), read(a), read(b);
	f[0] = ans = 1;
	int lim = min(n, a + b), d = getGcd(a, b);
	for (R int i = 1, num = 1; i <= lim; ++i) {
		while (que.size()) que.pop();
		if (i >= a && f[i - a])
			f[i] = 1, ++num, que.push(i);
		while (que.size()) {
			int now = que.front();
			que.pop();
			if (now >= b && !f[now - b])
				f[now - b] = 1, ++num, que.push(now - b);
			if (now + a <= i && !f[now + a])
				f[now + a] = 1, ++num, que.push(now + a);
		}
		ans += num;
	}
	cout << (ans + getSum(n + 1, d) - getSum(lim + 1, d));
	return 0;
}

#include<bits/stdc++.h>
#define N 20000005
#define ll long long
using namespace std;
int a, b, dis[N];
ll m, ans = 0;
bool vis[N];
queue <int> q;

inline int read() {
	int red = 0, f_f = 1; char ch = getchar();
	while(ch>'9' || ch <'0') {if(ch=='-') f_f = -1;	ch = getchar();}
	while(ch>='0' &&ch<='9') red = red*10+ch-'0', ch = getchar();
	return red*f_f;
}

void bfs() {
	q.push(0ll);
	vis[0] = 1, dis[0] = 0;
	while(!q.empty()) {
		int nw = q.front();
//		printf("%d\n", nw);
		q.pop(); vis[nw] = 0;
		if(nw+a <= m && dis[nw+a] > max(dis[nw], nw+a)) {
			dis[nw+a] = max(dis[nw], nw+a);
			if(!vis[nw+a]) { vis[nw+a] = 1; q.push(nw+a); }
		}
		if(nw-b >= 0 && dis[nw-b] > dis[nw]) {
			dis[nw-b] = dis[nw];
			if(!vis[nw-b]) { vis[nw-b] = 1; q.push(nw-b); }
		}
//		if(clock() >= 935) return;
	}
}

int main() {
	scanf("%lld\n", &m);
	a = read(), b = read();
	if(a == b) {
		ll tmp = m/a;
		printf("%lld\n", (m+1 + m - tmp * a + 1) * (tmp + 1) /2);
		return 0;
	}
	if(m <= 20000000) {
		memset(dis, 63, sizeof(dis));
//		memset(vis, 0, sizeof(vis));
		bfs();
		ans = m+1;
		for(int i = 1; i <= m; ++i)
			if(dis[i] <= m) ans += m - dis[i] + 1;
		printf("%lld\n", ans);
	}
	else printf("spfa-ak-ioi,wxw-ak-ioi!\n");
	return 0;
}

/* Burung ini cuma template
░░   ▄▀▀▀▄░░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/

#include<bits/stdc++.h>
#define mp make_pair
#define fs first
#define sc second
#define pb push_back
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mod 1000000007
#define INF 1e18
#define ALPHABET_SIZE 26

using namespace std;
typedef long long ll;

using namespace std;

long long nyak[200005];

bool ada[200005];
long long cnt = 0;

int gcd(int a,int b){
	if(b == 0) return a;
	return gcd(b, a % b);
}

int main(){
	long long m, a, b;

	memset(ada, false, sizeof(ada));

	cin >> m >> a >> b;

	int g = gcd(a, b);
	a /= g;
	b /= g;

	nyak[0] = 1; cnt++;
	ada[0] = true;
	for(int i = 1; i <= a + b - 1; i++){
		int x = i - a;
		if(x >= 0 && ada[x]){
			ada[i] = true;
			cnt++;

			int y = i - b;
			while(y >= 0 && !ada[y]){
				ada[y] = true;
				cnt++;
				y -= b;
			}
		}
		nyak[i] = cnt;
		// if(i != nyak[i] - 1) cout << i << " " << nyak[i] << " ini\n";
	}

	if(m < g * (a + b - 1)){
		long long ans = 0;

		for(int i = 0; i < m / g; i++){
			ans = ans + nyak[i] * g;
		}
		ans = ans + nyak[m / g] * ((m % g) + 1);

		cout << ans << "\n";
	}else{
		long long ans = 0;

		for(int i = 0; i <= a + b - 2; i++){
			ans = ans + nyak[i] * g;
		}

		long long x = a + b - 1, y = m / g - 1;
		if(x <= y){
			//dari a + b sampe m/g
			long long p = x + y + 2, q = y - x + 1;
			long long cur = (p * q) / 2;

			cur = cur * g;
			ans = ans + cur;
		}

		long long r = m / g + 1;
		ans = ans + r * ((m % g) + 1);

		cout << ans << "\n";
	}

}

#include <bits/stdc++.h>

using namespace std;

long long m, a, b;

long long ans;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	cin >> m >> a >> b;
	vector<long long> x(a, -1);
	for (long long i = 0, X = 0; x[i % a] == -1;)
	{
		x[i % a] = X;
		i += a;
		if (i <= m)
		{
			X = max(X, i);
			while (i >= b)
			{
				long long f = i % a;
				if (x[f] == -1)
					x[f] = X;
				i -= b;
			}
		} else
			break;
	}
	for (long long i = 0; i < a; i++)
	{
		if (x[i] != -1)
		{
			long long n = (m - i) / a + 1;
			long long N = (m - x[i]) / a + 1;
			ans += n-N + N*(m - x[i] + 1) - a*(N - 1) * N / 2;
		}
	}
	cout << ans;
	return 0;
}

#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 0;
const int OOO = 1;
using namespace std;

int gcd(int x, int y) {
	return !y ? x : gcd(y, x % y);
}

ll L, m, a, b;
ll ans = 1;

int cnt = 1;
bool vis[200005] = {};

void go(int x) {
	if (vis[x]) return;
	vis[x] = 1;
	cnt++;
	if (x + a <= L) go(x + a);
	if (x - b >= 0) go(x - b);
}

ll org;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> m >> a >> b;
	org = m;
	ll g = gcd(a, b);
	a /= g;
	b /= g;
	ll left = m % g;
	left = g - 1 - left;
	m /= g;
	vis[0] = 1;
	L = 1;
	while (L <= 200000 && L <= m) {
		if ((L - a >= 0 && vis[L - a])) go(L);
		if (OO) {
			cout << "L cnt " << L << " " << cnt << '\n';
		}
		ans += cnt;
		L++;
	}
	if (L > m) {
		ans *= g;
		ans -= cnt * left;
		finish(ans);
	}
	// sum L to m
	if (OO) cout << "ans " << ans << '\n';
	ans = (ans + (m + L + 2) * (m - L + 1) / 2);
	ans *= g;
	ans -= (org + 1) * left;
	finish(ans);
}

#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <ctime>
#include <random>
#include <bitset>

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

int gcd(int a, int b) {
	return (b == 0 ? a : gcd(b, a % b));
}

const int maxn = (int)3e5 + 10;
int ans[maxn];

ll solve(ll x, ll g, ll f) {
	ll c = (x - f) / g + 1;
	x -= c * g;
	return ans[x] + c;
}

int main() {
	int m, a, b;

	cin >> m >> a >> b;

	int f = a + b;

	int g = gcd(a, b);

	for (int i = 0; i < a; i++) {
		ans[i] = 1;
	}

	int prev = 0;
	int numb = 1;

	for (int i = a; i < f; i++) {
		while (true) {
			while (prev > b) {
				prev -= b;
				numb++;
			}

			if (prev + a <= i) {
				prev += a;
				numb++;
			}
			else {
				break;
			}
		}

		ans[i] = numb;
	}

	ll sum = 0;

	for (int i = f - g; i < f; i++) {
		sum += ans[i];
	}

	ll res = 0;

	while (m >= 0 && m % g != g - 1) {
		res += solve(m, g, f);
		m--;
	}

	if (m >= f) {
		ll c = (m - f + 1) / g;
		res += c * (c + 1) / 2 * g;
		res += c * sum;
		for (int i = 0; i < f; i++) {
			res += ans[i];
		}
	}
	else {
		for (int i = 0; i <= m; i++) {
			res += ans[i];
		}
	}

	cout << res << endl;

	//system("pause");

	return 0;
}

//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

signed main()
{
    fast;
    int m , a , b;
    cin >> m >> a >> b;

    vector< int > period( a+b,-1 );
    int cur = 0;
    int mx = 0;
    do
    {
        period[cur] = mx;
        if( cur < b ) cur += a;
        else          cur -= b;
        mx = max( mx,cur );
    }while( cur!=0 );
    int ans = 0;
    for(int i=0 ; i< min(m+1,a+b) ; i++ )
    {
        if( period[i] != -1 )
        {
            //cout << ans << '\n';
            int j = period[i];
            if( j > m ) continue;
            int times = ( m-j )/(a+b) + 1;
            ans += (m*times);

            //cout << ans << '\n';
            j--;
            int first_term = j;
            int last_term =  first_term + (times-1)*(a+b);
            int sn = (times * ( first_term + last_term ) )/2;

            ans -= sn;
            //cout << ans << "\n\n";
        }
    }
    cout << ans;
}

#include <cctype>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <stack>
#include <fstream>
#include <bitset>
#include <ctime>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ft first
#define sd second
#define all(x) (x).begin(),(x).end()
#define mfor(i,b,e) for(int i=b;i<e;i++)

vector<int> v;
long long  a, b,h=2;
long long req(int n) {
	long long sum=1;
	if (n + a < h && v[n+a]==0) {
		v[n + a] = 1;
		sum += req(a + n);
	}
	if (n - b > 0 && v[n - b] == 0) {
		v[n - b] = 1;
		sum += req(n - b);
	}
	return sum;
}
long long gcd(long long a, long long b) {
	return a ? gcd(b % a, a) : b;
}
int main()
{
	long long m,ans=2,k=1,z;
	cin >> m >> a >> b;
	z = gcd(a, b);
	if (a == 1) {
		cout << (m + 1) * (m + 2) / 2 <<endl;
		return 0;
	}
	v.resize((a + b + 1)*10);
	v[0] = 1;
	while ( h<=m) {
		if (h >= a && v[h-a]==1) {
			v[h] = 1;
			k += req(h);
		}
		ans += k;
		h++;
		if (k*z == h)
			break;
	}
	//h = min(h, m);
	ans += (m+1) * (m+2 ) / 2 - h * (h + 1) / 2;
	cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())

class Application {
private:

public:
    void run() {
        int m;
        int a, b;
        cin >> m >> a >> b;
        int d = __gcd(a, b);
        int should_be_visited = 0;
        int visited = 0;
        for (int i = 0; i < a + b; i++)
            if (i % d == 0)
                should_be_visited++;
        vector<int> v(a + b, -1);
        int current_max = 0;
        int k = 0;
        while (true) {
            if (v[k] == -1) {
                v[k] = current_max;
                visited++;
                if (visited == should_be_visited)
                    break;
            }
            if (k >= b) {
                k -= b;
            } else {
                k += a;
                current_max = max(current_max, k);
            }
        }
        ll result = 0;
        for (int i = 0; i < a + b && i <= m; i += d) {
            if (v[i] <= m)
                result += m - v[i] + 1;
        }
        int start = a + b;
        while (start % d != 0)
            start++;
        int end = m;
        while (end % d != 0)
            end--;
        if (start >= end) {
            cout << result;
            return;
        }
        ll t = (end - start) / d;
        result -= d * t * (t + 1) / 2;
        result += (t + 1) * (1ll + m - start);
        cout << result;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    Application app;
    app.run();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef complex<ld> pt;
typedef vector<pt> pol;

const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

struct Node {
	int id, dist;
	bool operator < (const Node& o) const {
		return dist > o.dist;
	}
};

//#define FILEIO
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(10);
#ifdef FILEIO
	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);
#endif

	int n, a, b;
	cin >> n >> a >> b;

	unordered_map<int,int> res;
	priority_queue<Node> dijk;
	dijk.push({0,0});
	res[0] = 0;
	while (!dijk.empty() && res.size()<5e6 && clock()<1.789*CLOCKS_PER_SEC) {
		Node cur = dijk.top();
		dijk.pop();
		int u = cur.id;
		int v = cur.dist;
		if (u-b >= 0 && !res.count(u-b)) {
			res[u-b] = max(u-b, v);
			dijk.push({u-b, max(u-b,v)});
		}
		if (!res.count(u+a)) {
			res[u+a] = max(u+a, v);
			dijk.push({u+a, max(u+a,v)});
		}
	}

	int g = __gcd(a,b);
	int k = (n+1)/g;
	ll ans = (ll)(k+1)*(n+1) - (ll)g*((ll)k*(k+1)/2);
	for (const auto& it : res) {
		if (it.first <= n) {
			ans += max(0, n-it.second+1) - (n-it.first+1);
		}
	}
	cout << ans << nl;

	return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
int m,a,b,d;
int gcd(int x,int y)
{
	if(y==0)
		return x;
	return gcd(y,x%y);
}
int f[1000005];
bool mark[1000005];
int cnt;
void dfs(int x)
{
	for(int i=1;i*b<x;i++)
	{
		if(mark[x-i*b])continue;
		mark[x-i*b]=1;
		cnt++;
		int tmp=x-i*b+a;
		while(tmp<x){
			if(!mark[tmp]){
				mark[tmp]=1;
				cnt++;
				dfs(tmp);
			}
			tmp+=a;
		}
	}
}
long long cal(long long x,long long y,long long d)
{
	long long ret=0;
	long long nx=x;
	if(x%d!=0)
		nx=(x/d+1)*d;
	long long ny=y/d*d-1;
	if(nx<=ny){
		long long numx=nx/d;
		long long numy=ny/d;
		ret+=(1+numy)*numy/2;
		ret-=(numx-1)*numx/2;
		ret*=d;
	}
	long long numx=nx-x;
	ret+=numx*(x/d);
	long long numy=y-ny;
	ret+=numy*(y/d);
	return ret;
}
int main()
{
	cin>>m>>a>>b;
	int d=gcd(a,b);
	long long ans=0;
	cnt=1;
	mark[0]=1;
	for(int i=0;i<min(m+1,a);i++){
		f[i]=1;
		ans+=f[i];
	}
	int st=a;
	for(int i=a;i<=min(m,10*max(a,b));i++)
	{
		int j=1;
		while(i-j*a>=0){
			if(mark[i-j*a]){
				mark[i]=1;
				cnt++;
				break;
			}
			j++;
		}
		if(mark[i]==0){
			f[i]=cnt;
			ans+=f[i];
			st=i+1;
			continue;
		}
		dfs(i);
		f[i]=cnt;
		ans+=f[i];
		st=i+1;
	}
	if(st<=m)
	{
		ans+=m-st+1;
		ans+=cal(st,m,d);
	}
	cout<<ans<<endl;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>

using namespace std;

long long m,a,b;

long long vis[500005];
long long inf=1e9+7;

void dfs(long long sta,long long maxx)
{

    vis[sta]=maxx;
    if(sta>47630)
        cout<<sta<<" "<<maxx<<endl;
    if(sta==47639)
        cout<<sta+a<<" "<<vis[sta+a]<<endl;
    if(sta-b>=0 && vis[int(sta-b)]==inf)
        dfs(sta-b,maxx);
    if(sta+a<=5000 && vis[int(sta+a)]==inf)
        dfs(sta+a,max(maxx,sta+a));

}

long long ggcd(long long x,long long y)
{
    if(y==0)
        return x;
    else
        return ggcd(y,x%y);
}
int main() {

    while(~scanf("%lld%lld%lld",&m,&a,&b))
    {
        for(int i=0;i<=500000;i++)
            vis[i]=inf;

        dfs(0,0);

        //cout<<"~"<<endl;
        long long maxn=0;
        for(int i=0;i<a;i++)
        {
            if(vis[i]!=inf)
                maxn=max(maxn,vis[i]);
        }

        long long ans=0;
        for(long long i=0;i<=min(m,500000ll);i++)
        {
            //if(vis[i]!=inf)
            {
                long long tp=max(vis[i%a],1ll*i);
                if(tp<=m)
                ans+=(m-tp+1);
                //cout<<i<<endl;
            }
        }

        //cout<<maxn<<endl;
        maxn=min(m,500000ll);
        if(m>maxn)
        {

            long long gcd=ggcd(a,b);
            long long tp1=maxn+1+(gcd-(maxn+1)%gcd)%gcd;
            long long tp2=m-m%gcd;
            long long cnt=(tp2-tp1)/gcd+1;

            long long ans1=(tp1+tp2)*cnt/2;
            ans+=cnt*(m+1)-ans1;

            //cout<<tp1<<" "<<tp2<<" "<<cnt<<endl;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double

#define pb push_back
#define ins insert
#define er erase

#define f(i, a, b) for (int i = a; i < b; ++i)
#define rf(i, a, b) for (int i = a; i >= b; --i)
#define mem(a, b) memset(a, b, sizeof(a))

#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vb vector<bool>
#define vst vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define all(v) v.begin(), v.end()
#define lb lower_bound
#define ub upper_bound
#define mxe max_element
#define mne min_element

#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())

#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second

#define bs bitset
#define bpc(a) __builtin_popcount(a)

#define mii map<int, int>
#define mll map<ll, ll>
#define umii unordered_map<int, int>
#define umll unordered_map<ll, ll>

#define si set<int>
#define sll set<ll>
#define usi unordered_set<int>
#define usll unordered_set<ll>
#define spii set<pii>
#define spll set<pll>

#define pqi priority_queue<int>
#define pqll priority_queue<ll>

#define dbg(a, st, end)                   \
    f(i, st, end + 1) cerr << a[i] << sp; \
    cerr << nl;
#define pnt(a, st, end)                   \
    f(i, st, end + 1) cout << a[i] << sp; \
    cout << nl;
#define dbgc(a)          \
    for (auto y : a)     \
        cerr << y << sp; \
    cerr << nl;
#define dbgm(a)                            \
    for (auto y : a)                       \
        cerr << y.ff << "," << y.ss << sp; \
    cerr << nl;

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)

#define nl "\n"
#define sp " "

using namespace std;
using namespace std::chrono;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>
#define ok order_of_key
#define fo find_by_order

//ll md = 1000000007;
ll md = 998244353;

ll pw(ll a, ll b)
{
    ll c = 1, m = a;
    while (b)
    {
        if (b & 1)
            c = (c * m);
        m = (m * m);
        b /= 2;
    }
    return c;
}

ll pwmd(ll a, ll b)
{
    ll c = 1, m = a;
    while (b)
    {
        if (b & 1)
            c = (c * m) % md;
        m = (m * m) % md;
        b /= 2;
    }
    return c;
}

ll modinv(ll n)
{
    return pwmd(n, md - 2);
}

ll my_ceil(ll a, ll b)
{
    if (a % b == 0)
        return a / b;
    return a / b + 1;
}

ll nc2(ll n)
{
    return (1ll * n * (n - 1)) / 2;
}

int my_log(ll n, int b)
{
    ll i = 1;
    int ans = 0;
    while (1)
    {
        if (i > n / b)
            break;
        i *= b;
        ans++;
    }
    return ans;
}

inline int nc()
{
    static char buf[100000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}
inline int read()
{
    int ret = 0;
    bool f = 0;
    char ch = nc();
    while (ch > '9' || ch < '0')
        f ^= ch == '-', ch = nc();
    while (ch <= '9' && ch >= '0')
        ret = ret * 10 + ch - '0', ch = nc();
    return f ? -ret : ret;
}

ll min(ll a, ll b)
{
    return (a < b ? a : b);
}

ll max(ll a, ll b)
{
    return a + b - min(a, b);
}

inline ll add(ll a, ll b) { return (((a >= md) ? a % md : a) + ((b >= md) ? b % md : b) + md) % md; }
inline ll subt(ll a, ll b) { return (a - b + md) % md; }
inline ll mult(ll a, ll b) { return (1ll * ((a >= md) ? a % md : a) * ((b >= md) ? b % md : b)) % md; }

inline bool kthbit(ll n, int k) { return (n >> k) & 1; }
inline ll setkthbit(ll n, int k) { return n | (1ll << k); }
inline ll unsetkthbit(ll n, int k) { return n & ~(1ll << k); }
inline ll flipkthbit(ll n, int k) { return n ^ (1ll << k); }

//LET'S PLAY THE GAME!!

int main()
{
    fast;

    ll l, r, e, h, k, n;
    ll x, q, c, m;

    string s, t;

    auto start = high_resolution_clock::now();

    int tcnt = 0;
    int tests = 1;
    //pre();
    //cin >> tests;

    while (tests--)
    {
        //cout << "Case #" << ++tcnt << ": ";
        ll a, b;
        cin >> m >> a >> b;
        ll st[a + b];
        mem(st, -1);
        h = gcd(a, b);
        st[0] = 0;
        if (a > b)
        {
            ll cur = a, mxcur = a;
            while (1)
            {
                if (st[cur] != -1)
                    break;
                mxcur = max(mxcur, cur);
                for (int i = cur; i > 0; i -= b)
                    st[i] = mxcur;
                cur = cur % b + a;
            }
        }
        else
        {
            ll cur = a * (b / a);
            if (cur < b)
                cur += a;
            ll mxcur = cur;
            while (1)
            {
                if (st[cur] != -1)
                    break;
                if(cur%a)mxcur = max(mxcur, cur);
                e = 0;
                for (int i = cur - b; i < a + b; i += a)
                    st[i] = mxcur, e = i;
                cur = e;
            }
            for (int i = 0; i < a + b; i += a)
                st[i] = i;
        }
        ll ans = 0;
        f(i, 0, min(a + b, m + 1)) if (st[i] != -1 && st[i] <= m) ans += (m - st[i] + 1);
        //dbgc(st);
        if (a + b > m)
        {
            cout << ans;
            return 0;
        }
        l = h * ((a + b) / h);
        if (l < a + b)
            l += h;
        c = h * (m / h);
        e = (c - l) / h + 1;
        r = m - c + 1;
        ans += (e * (2 * r + (e - 1) * h)) / 2;
        cout << ans;
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cerr << "Time taken: "
         << duration.count() / 1000000.0 << "seconds" << nl;
    return 0;
}

// AND THE GAME IS OVER !!

#include <bits/stdc++.h>
using namespace std;
#define io_speed_up ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,a,b) for (int i=a;i>=b;i--)
#define ms(a,b)  memset(a,b,sizeof a)
#define sz(x) (int)x.size()
using ll = long long;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6+5;
ll m, a, b;
int f[maxn];
int cnt;
void dfs(int x,int lim)
{
    if((x-a>=0 && f[x-a]) || (x+b<=lim && f[x+b])){
        f[x] = 1;
        cnt++;
    }
    if(f[x]) {
        if(x-b>=0 && !f[x-b]) dfs(x-b,lim);
        if(x+a<=lim && !f[x+a]) dfs(x+a,lim);
    }
}
int main()
{
    cin >> m >> a >> b;
    ll g = __gcd(a, b);
    cnt = 1;
    f[0] = 1;
    int x = 1;
    ll ans = 1;
    while(x<=m) {
        dfs(x,x);
        if(x>=a && cnt == x/g+1) break;
        ans += cnt;
        x++;
    }
    // cout << x << endl;
    // while(x<=m) {
    //     ans += x / g + 1;
    //     x++;
    // }
    if(x<=m) {
        ans += m - x + 1;
        int l = x, r = m;
        while(l<=m && l%g != 0) {
            ans += l / g;
            l++;
        }
        while(r>l && r%g != 0) {
            ans += r / g;
            r--;
        }
        if(r>l) {
            ans += r / g;
            r--;
        }
        int k = (r - l + 1) / g;
        ans += 1LL * (l / g + l / g + k - 1) * k / 2 * g;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

#define err(A) cout << #A << " = " << (A) << endl

using namespace std;

int gcd(int x, int y) {
    if (x % y == 0)
        return y;
    return gcd(y, x % y);
}

long long ans = 0, m, a, b;

int main() {
    cin >> m >> a >> b;
    long long cnt = 1, lastPoint = 0;
    for (int i = 0; i < min(a + b, m+1); i++) {
        while (lastPoint + a <= i or lastPoint - b > 0) {
            if (lastPoint + a <= i)
                lastPoint += a;
            else
                lastPoint -= b;
            cnt++;
        }
        ans += cnt;
    }
    long long i = a + b, g = gcd(a, b);
    if (i % g != 0) {
        ans += ((i / g) + 1) * (g - (i % g));
        i += g - (i % g);
    }
    if (m % g != g - 1) {
        ans += ((m / g) + 1) * ((m % g) + 1);
        m -= ((m % g) + 1);
    }
    i /= g;
    i++;
    m /= g;
    m++;
    if (m >= i) {
        long long x = m - i + 1, y = m + i;
        if (x % 2 == 0)
            x /= 2;
        else
            y /= 2;
        ans += x * y * g;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5+10;
int f[maxn*10];
int minPos[maxn * 10];
int dp[maxn * 10];

void dfs(int u, int a,int b) {
	priority_queue<int> q;
	q.push(0);
	f[0] = true;
	minPos[0] = 0;
	while (!q.empty()) {
		int u = -q.top();
		q.pop();
		if (u + a < maxn * 10 && !f[u+a]) {
			int v = u + a;
			q.push(-v);
			minPos[v] = max(v, minPos[u]);
			f[v] = true;
		}
		//if (u == 7) cerr << "xxx " << f[u-a] << endl;
		if (u - b >= 0 && !f[u-b]) {
			int v = u - b;
			q.push(-v);
			minPos[v] = minPos[u];
			f[v] = true;
		}
		//q.pop();
	}
}

long long get(int l,int r, int t) {
	while (l%t) l++;
	if (l>r) return 0;
	return (r - l) / t + 1;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m, a, b;
	cin >> m >> a >> b;
	int t = max(a,b);
	memset(minPos, -1,sizeof(minPos));
	dfs(0, a, b);
	//cerr << "asdf" << endl;
	priority_queue<int> q;
	//for(int i=0;i<20;i++) cerr << i <<" " <<f[i] <<" " <<minPos[i] << endl;
	for(int i=0;i<maxn * 10;i++) {
		if (i) dp[i] = dp[i-1];
		if (f[i]) {
			q.push(-minPos[i]);
		}

		while (q.size() && -q.top() <=i) {
			dp[i]++;
			q.pop();
		}
	}
	//for(int i=0;i<10;i++) cout <<"ttt " << i<<" "<< dp[i] <<endl;
	long long res = 0;

	if (m > maxn * 4) {
		for(int i=0;i<maxn * 4;i++) {
			res += dp[i];
		}
		int t = __gcd(a,b);
		res += 1ll * dp[maxn * 4 - 1] * (m - maxn * 4 + 1);
		long long tmp = get(maxn * 4, m, t);
		res += (tmp * (tmp + 1)) / 2 * t;
		res -= (maxn * 4 + tmp * t -1 - m) * tmp;
	} else {
		for(int i=0;i<=m;i++) {
			res += dp[i];
		}
	}
	cout << res;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX=1e6+5;
ll MOD=1e9+7;
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fbo find_by_order
#define ook order_of_key
#define up upper_bound
#define lb lower_bound
#define pq priority_queue
#define pll pair<ll,ll>
using namespace __gnu_pbds;
#define boost               ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll add(ll a,ll b){return (a+b)%MOD;}
ll mul(ll a,ll b){return (a*b)%MOD;}
ll visited[MAX];
int main()
{
	boost;
	ll m,a,b,ans=0;
	cin>>m>>a>>b;
	ordered_set s;
	pq<ll,vector<ll>,greater<ll>>q;
	visited[0]=1;
	q.push(0);
	s.insert(0);
	for(ll i=0;i<=min(m,(ll)2e5);i++){
		while(q.size() && q.top()<=i){
			ll x=q.top();
			q.pop();
			if(!visited[max((ll)0,x-b)]){
				visited[x-b]=1;
				q.push(x-b);
				s.insert(x-b);
			}
			if(!visited[x+a]){
				visited[x+a]=1;
				q.push(x+a);
				s.insert(x+a);
			}
		}
		ans+=s.ook(i+1);
	}
	if(m<=2e5){
		cout<<ans;
		return 0;
	}
	ll x=__gcd(a,b);
	debug(x);
	ll y=2e5+1;
	//debug2((y*(y+1))/2,ans);
	ll a1=m/x,b1=(y)/x;
	ll c=m%x,d=(y)%x;
	ans+=(((a1-b1+1)*(a1+b1))/2)*x;
	ans-=(b1+1)*d+(a1+1)*(x-c-1);
	cout<<ans+(a1-b1+1)*x;

}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool used[200001];
long long a, b, x, now = 1, ans = 1;

void go(int v) {
	used[v] = true;
	now++;
	if (v >= b && !used[v - b])
		go(v - b);
	if (v + a <= x && !used[v + a])
		go(v + a);
}

long long gcd(long long a, long long b) {
	if (a > b)
		swap(a, b);
	if (a == 0)
		return b;
	return gcd(b % a, a);
}

int main() {
	long long m;
	cin >> m >> a >> b;
	used[0] = true;
	for (x = 1; x <= min(m, a + b); x++) {
		if (x >= a && used[x - a])
			go(x);
		ans += now;
	}
	long long g = gcd(a, b);
	//cout << ans << endl;
	if (a + b < m) {
		x = a + b + 1;
		while (x <= m && x % g != 0) {
			ans += x / g;
			x++;
		}
		//cout << ans << endl;
		x /= g;
		long long y = m / g - 1;
		ans += g * ((y * (y + 1)) / 2 - (x * (x - 1)) / 2);
		//cout << ans << endl;
		x = (y + 1) * g;
		while (x <= m) {
			ans += x / g;
			x++;
		}
	}
	cout << ans;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define int ll

const int N = 3e6;

bool mark[N];

int m, a, b;

int gcd(int a, int b){
    if(b == 0)
        return a;
    a %= b;
    return gcd(b, a);
}

int f(int d){
    int g = gcd(a, b);
    if(d/g == 0)
        return 0;
    int n = d/g;
    int ret = n*(n-1)/2;
    ret += (d - (d/g)*g) * (d/g);
    return ret;
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> m >> a >> b;
    int g = gcd(a, b);
    m /= g;
    a /= g;
    b /= g;

    mark[0] = true;
    set<int> st;
    st.insert(a);
    int ans = 0;
    int cnt = 1;
    for(int i=0 ; i<2e6 ; i++){
        while((int)st.size() && *st.begin()<=i){
            int x = *st.begin();
            st.erase(st.begin());
            if(mark[x])
                continue;
            mark[x] = true;
            cnt ++;
            if(x+a <= m && mark[x+a] == false)
                st.insert(x+a);
            if(x-b >= 0 && mark[x-b] == false)
                st.insert(x-b);
        }
        ans += cnt;
        if(i == m){
            cout << ans << "\n";
            return 0;
        }
    }
    int len = (m - int(2e6) + 1);
    cout << ans + f(m+1) - f(2e6) + len << "\n";

}

//By TheOneYouWant

#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e;++i)
#define forsn(i,s,e) for(int i = s; i < e;++i)
#define rforn(i,s) for(int i = s; i >= 0;--i)
#define rforsn(i,s,e) for(int i = s; i >= e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime ((double)clock()/CLOCKS_PER_SEC)
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
    c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;

const int LIM=1e6+5, MOD=1e9+7;
const int MAX = 1000000;
const ld EPS = 1e-9;
// int t,n,m,k,x,y,w;

bool visited[LIM];
int dist[LIM];
int m,a,b;

void dfs(int node, int ma){

    visited[node] = 1;

    if(node-b>=0){
        if(visited[node-b]==1);
        else {
            dist[node-b] = min(dist[node-b],dist[node]);
            dfs(node-b,ma);
        }
    }

    if(node+a<=ma){
        if(visited[node+a]==1) ;
        else {
            dist[node+a] = min(dist[node+a],max(dist[node],node+a));
            dfs(node+a,ma);
        }
    }

}

signed main(){
    fastio;

    // int m,a,b;
    cin>>m>>a>>b;
    // visited[0]=1;
    forn(i,LIM){
        dist[i] = 1e9;
    }
    dist[0] = 0;
    if(m<=MAX){
        dfs(0,m);
        ll cnt=0;
        forn(i,m+1){
            if(visited[i]) {
                // cout<<i<<" "<<dist[i]<<ln;
                cnt+=m-dist[i]+1;
            }
        }
        cout<<cnt<<ln;
    }
    else{
        dfs(0,MAX);
        ll cnt=0;
        forn(i,MAX+1){
            if(visited[i]) {
                // cout<<i<<" "<<dist[i]<<ln;
                cnt+=m-dist[i]+1;
            }
        }
        ll z = __gcd(a,b);
        ll r = m/z;
        ll l = MAX/z;
        cnt-= ((r*(r+1))/2 - (l)*(l+1)/2)*z;
        cnt+= (r-l)*(m+1);
        cout<<cnt<<ln;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

bool vis[1'000'000+100];

ll m,a,b;
ll dfs(ll at, ll i) {
    if(at < 0 || at > i) return 0;
    if(vis[at]) return 0;
    vis[at] = true;
    ll cnt = 1;
    cnt += dfs(at+a,i)+dfs(at-b,i);
    return cnt;
}

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b,a%b); }

ll to(ll r, ll div) {
    if(r == 0) return 0;
    return r/div;
}

ll range(ll l, ll r, ll div) {
    return to(r,div)-to(l-1,div);
}

int main() {
    cin.sync_with_stdio(false);
    memset(vis,0,sizeof(vis));
    cin >> m >> a >> b;
    ll sol = 0;
    sol += (m+1);
    vis[0] = true;
    rep(i,1,min(1'000'001LL,m+1)) {
        if(i-a >= 0 && vis[i-a]) {
            ll val = dfs(i,i);
            sol += (m-i+1)*val;
        }
    }
    if(m > 1'000'000) {
        if(gcd(a,b) == 1) {
            ll val = range(1'000'001LL, m, 1);
            sol += (val*(val+1))/2;
        } else {
            ll start = 1'000'0001LL+gcd(a,b);
            if(start <= m)  {
                while(sol <= m) {
                    ll left = m-start+1;
                    sol += left;
                    sol += gcd(a,b);
                }
            }
        }
    }

    cout << sol << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long int

#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define _cin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()

#define INF 2147483647
#define MAXN 2000004
#define endl "\n"

ll mod = 1000000007;

ll vis[MAXN];

ll getSum(ll a, ll b)
{
    ll x, y;
    a--;
    x = (a * (a + 1)) / 2;
    y = (b * (b + 1)) / 2;
    return y - x;
}

ll getNum(ll n, ll hcf)
{
    return 1 + (n / hcf);
}

int main()
{
    _cin;
    ll m, a, b, tmp, sum, left, rem, comp;
    cin >> m >> a >> b;
    ll num = 1, last = 0, ans = 1, tot = 1, flag = 0, curr, hcf = __gcd(a, b), res;
    vis[0] = 1;
    while(num <= 2 * (a + b) && num <= m){
        res = getNum(num - 1, hcf);
        if(num >= (a + b) && res == tot){
            break;
        }
        //cout << "ans = " << ans << " num = " << num << " tot = " << tot << " curr = " << curr << " last = " << last << " flag = " << flag << endl;
        curr = tot;
        while(1){
            tmp = curr;
            while(last - b > 0 && vis[last - b] == 0){
                last -= b;
                vis[last] = 1;
                curr++;
            }
            while(last + a <= num && vis[last + a] == 0){
                last += a;
                vis[last] = 1;
                curr++;
            }
            if(tmp == curr) break;
        }
        tot = curr;
        ans += tot;
        num++;
    }
    if(num > m){
        cout << ans << endl;
    }
    else{
        num -= 2;
        ans -= tot;
        left = m - num;
        rem = left % hcf;
        comp = left / hcf;
        sum = getSum(tot, tot + comp - 1);
        sum = sum * hcf;
        ans += sum;
        tot += comp;
        ans += tot * rem;
        cout << ans << endl;
    }
    return 0;
}

/////////////////////////   _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 + 3;

int m , a , b;

int gcd(int a,int b){
    if(b == 0)return a;
    return gcd(b , a % b);
}

int f[N];
bool used[N];

set <int> q;

int main() {
	mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> m >> a >> b;
    int g = gcd(a , b);
    int n = a + b - g;
    used[0] = true;
    q.insert(0);
    int x = 0;
    while(!q.empty()){
        int v = (*q.begin());
        q.erase(q.begin());
        x = max(x , v);
        f[x]++;
        if(v + a <= n && used[v + a] == false){
            used[v + a] = true;
            q.insert(v + a);
        }
        if(v - b >= 0 && used[v - b] == false){
            used[v - b] = true;
            q.insert(v - b);
        }
    }
    long long answ = 0 , s = 0;
    n = min(n , m);
    for(int i=0;i<=n;i++){
        s += f[i];
        answ += s;
    }
    if(m <= n){
        cout << answ << endl;
        return 0;
    }
    if(m - n < g){
        m -= n;
        answ += m * 1ll * s;
        return 0;
    }
    m -= n + g - 1;
    answ += (g - 1) * 1ll * s;
    ++s;
    long long sz = m / g;
    if(sz){
        answ += g * 1ll * (2 * s + sz - 1) * 1ll * sz / 2;
    }
    m %= g;
    while(m--){
        answ += s + sz;
    }
    cout << answ << endl;
	return 0;
}

/*---------------Go Code GO---------------*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using Order_Set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define     PI              acos(-1.0)
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     precision(a)    fixed<<setprecision(a)
#define     endl            '\n'
#define     Flush           cout<<flush
#define     LLMX            0x3fffffffffffffff

long long M,A,B;
long long Ans[3000005];

int main()
{
    long long i,j,k,l,tst=0,ans=0, csno=0, pointer=0;
    cin>>M>>A>>B;
    Ans[0]=1;
    pointer = A;
    for(i=1; i<(A+B); i++)
    {
        while(pointer<=i)
        {
            Ans[i]++;
            while(pointer-B>0)
            {
                pointer-=B;
                Ans[i]++;
            }
            pointer+=A;
        }
        Ans[i]+=Ans[i-1];
        //cout<<Ans[i]<<' '<<endl;
    }
    for(i=1; i<(A+B); i++) Ans[i]+=Ans[i-1];
    if(M<A+B)
    {
        cout<<Ans[M]<<endl;
        return 0;
    }
    long long multp , last_n, first_n, extra, nmbrMultp, total;

    multp = __gcd(A,B);
    first_n = (A + B)/multp;

    last_n = (M/multp);

    total = multp*((last_n+1)*(last_n)-(first_n-1)*first_n)/2;
    total+= last_n*(M%multp)+Ans[A+B-1]+M+1-(A+B);
    cout<<total<<endl;

//    total = multp*(nmbrMultp*firstMultp+multp*(((nmbrMultp-1)*nmbrMultp)/2))+nmbrMultp;
//    total+=lastMultp*(M-lastMultp+1)+Ans[A+B-1]+1;

    cout<<total<<endl;

    return 0;
}