#include <bits/stdc++.h>
int main() {
  int n, x;
  int big;
  int min = 1;
  int first, secound;
  int rem;
  int sum = 0;
  int i, j;
  scanf("%d%d", &n, &x);
  first = x;
  sum += first;
  secound = n - first;
  sum += secound;
  for (; first != secound;) {
    min = secound;
    for (; min - first > 0;) {
      sum += first * 2;
      min -= first;
    }
    secound = first;
    first = min;
    printf("%d,%d,%d\n", first, secound, min);
  }
  sum += 2 * first;
  sum -= first;
  printf("%d\n", sum);
  return 0;
}
