#include <bits/stdc++.h>
using namespace std;
long long m, a, b, sol, lst, ma, t;
long long nr, f;
long long gaus(long long n) {
  n *= n + 1;
  n /= 2;
  return n;
}
long long solve(long long n, long long m) {
  long long ret;
  ret = n * m;
  ret -= gaus(n - 1) * a;
  return ret;
}
int main() {
  cin >> m >> a >> b;
  sol = solve((m / a) + 1, m + 1);
  lst = b;
  while (b % a) {
    while (t < lst) {
      nr++;
      t += a;
    }
    ma = max(ma, t);
    if (t > m) break;
    t -= lst;
    sol += (((ma - t) / a) + 1) * (m - ma + 1);
    f = t;
    f += (((ma - t) / a) + 1) * a;
    b += lst;
    if (f > m) continue;
    sol += solve(1 + (m - f) / a, m - f + 1);
  }
  cout << sol;
}
