import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


/*
  a[0] = 0
  a[i] = (D + 1) a[i - 1] + D i
  
  a[i] - 2 a[i - 1] + a[i - 2] = (D + 1) a[i - 1] - 2 (D + 1) a[i - 2] + (D + 1) a[i - 3]
  T^3 - (D + 3) T^2 + (2 D + 3) T - (D + 1)
*/

enum MO = 10L^^9 + 7;
enum INF = 3 * 10L^^18;
enum LIM = 100;

long[] mul(long[] a, long[] b, long D) {
  auto c = new long[5];
  foreach (i; 0 .. 3) foreach (j; 0 .. 3) {
    c[i + j] += a[i] * b[j];
  }
  c[] %= MO;
  foreach_reverse (i; 3 .. 5) {
    c[i - 1] = (c[i - 1] + (    D + 3) * c[i]) % MO;
    c[i - 2] = (c[i - 2] - (2 * D + 3) * c[i]) % MO;
    c[i - 3] = (c[i - 3] + (    D + 1) * c[i]) % MO;
  }
  return c[0 .. 3];
}

long getFull(long k, long D) {
  debug {
    enum lim = 10;
    auto a = new long[lim];
    a[0] = 0;
    foreach (i; 1 .. lim) {
      a[i] = ((D + 1) * a[i - 1] + D * i) % MO;
    }
    writeln(a);
    foreach (i; 3 .. lim) {
      assert((a[i] - (D + 3) * a[i - 1] + (2 * D + 3) * a[i - 2] - (D + 1) * a[i - 3]) % MO == 0);
    }
  }
  long[] x = [0, 1, 0], y = [1, 0, 0];
  for (long e = k; e; e >>= 1) {
    if (e & 1) {
      y = mul(y, x, D);
    }
    x = mul(x, x, D);
  }
  const a2 = ((D + 1) * D + D * 2) % MO;
  const ret = (y[1] * D + y[2] * a2) % MO;
  debug {
    writeln("getFull ", k, " ", D, " = ", ret);
  }
  return ret;
}

long[] len;

long calc(int k, long D, long a, long b) {
  chmax(a, 0);
  chmin(b, len[k]);
  if (a >= b) {
    return 0;
  }
  long ret;
  if (a == 0 && b == len[k]) {
    ret = getFull(k, D);
  } else {
    const m = len[k - 1] + 1;
    if (a / m == b / m) {
      ret = calc(k - 1, D, a % m, b % m);
    } else {
      ret += calc(k - 1, D, a % m, m - 1);
      ret += (b / m - a / m - 1) * getFull(k - 1, D);
      ret += (b / m - a / m) * k;
      ret += calc(k - 1, D, 0, b % m);
      ret %= MO;
    }
  }
  debug {
    writeln("calc ", k, " ", D, " ", a, " ", b, " = ", ret);
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      const N = readLong();
      const B = readLong();
      const D = readLong();
      
      len = new long[LIM];
      len[0] = 0;
      foreach (i; 1 .. LIM) {
        len[i] = cast(long)(min((D + 1) * BigInt(len[i - 1]) + D, BigInt(INF)));
      }
      debug {
        writeln("len = ", len);
      }
      
      long ans = getFull(B, D);
      foreach (i; 0 .. LIM) {
        if (N <= len[i]) {
          ans -= calc(i, D, 0, N);
          break;
        }
      }
      ans = (ans % MO + MO) % MO;
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}