Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number.

For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. 

Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7).

A number's length is the number of digits in its decimal representation without leading zeroes.


-----Input-----

The first line contains three integers: a, b, n (1 ≤ a < b ≤ 9, 1 ≤ n ≤ 10^6).


-----Output-----

Print a single integer — the answer to the problem modulo 1000000007 (10^9 + 7).


-----Examples-----
Input
1 3 3

Output
1

Input
2 3 10

Output
165

Difficulty: MEDIUM_HARD
Tags: Combinatorics

Complete search
Skill types: Complete search

Starter code:

Solutions:
ans = 0
mod = 1000000007
(a, b, n) = list(map(int, input().split()))
s = set()
for x in range(2, 1 << 8):
	z = 0
	while x > 1:
		z = z * 10 + (a, b)[x & 1]
		x >>= 1
	s.add(z)
f = [1] * (n + 1)
for i in range(1, n + 1):
	f[i] = f[i - 1] * i % mod
for x in range(n + 1):
	if x * a + (n - x) * b in s:
		ans += pow(f[x] * f[n - x], mod - 2, mod)
		ans %= mod
print(ans * f[n] % mod)


import sys
import itertools as it
import math as mt
import collections as cc
input = sys.stdin.buffer.readline
I = lambda : list(map(int, input().split()))
(a, b, n) = I()
fact = [1] * (n + 1)
mod = 10 ** 9 + 7
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i
	fact[i] %= mod

def ch(n, a, b):
	f = 1
	while n:
		if n % 10 != a and n % 10 != b:
			f = 0
			break
		n //= 10
	return f
ans = 0
for i in range(n + 1):
	x = i * a + (n - i) * b
	if ch(x, a, b):
		ans += fact[n] * (pow(fact[i], mod - 2, mod) % mod) * pow(fact[n - i], mod - 2, mod)
		ans %= mod
print(ans)


from bisect import bisect_right, bisect_left
(a, b, n) = list(map(int, input().split()))
if a > b:
	(a, b) = (b, a)
(u, v) = (10 * a, 10 * b)
(x, y) = (a * n, b * n)
(t, d) = ([a, b], b - a)
while t[-1] < x:
	t = [j + u for j in t] + [j + v for j in t]
	(u, v) = (u * 10, v * 10)
if t[-1] < y:
	t += [j + u for j in t] + [j + v for j in t]
(t, s) = (t[bisect_left(t, x):bisect_right(t, y)], 0)
(m, f) = (1000000007, [1] + [0] * n)
(p, k) = (list(range(x, y + 1, d)), 0)
for i in range(1, n + 1):
	f[i] = f[i - 1] * i % m
for i in t:
	k = bisect_left(p, i)
	if p[k] == i:
		s += pow(f[k] * f[n - k], m - 2, m)
print(s % m * f[n] % m)


def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
(a, b, n) = map(int, input().split())
ans = 0
p = 10 ** 9 + 7
num = 1
den = 1
for i in range(n + 1):
	s = a * i + b * (n - i)
	if i != 0:
		num = num * (n - i + 1) % p
		den = den * i % p
	am = True
	while s != 0:
		if s % 10 != a and s % 10 != b:
			am = False
			break
		s //= 10
	if am:
		ans = (ans + num * pow(den, p - 2, p) % p) % p
print(ans % p)


import math
import time
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import PriorityQueue
import sys
MOD = int(1000000000.0 + 7)

def good(x):
	while x > 0:
		if x % 10 != a and x % 10 != b:
			return False
		x = x // 10
	return True

def ncr(n, r):
	return fact[n] * pow(fact[i] * fact[n - i], MOD - 2, MOD) % MOD
(a, b, n) = map(int, stdin.readline().split())
fact = [1] * (n + 2)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i
	fact[i] %= MOD
ans = 0
temp = b * n
for i in range(n + 1):
	if good(temp):
		ans += ncr(n, i)
	temp += a - b
print(ans % MOD)


N = 10 ** 6
mod = 10 ** 9 + 7

def checkgood(val, a, b):
	while val:
		if val % 10 != a and val % 10 != b:
			return False
		val //= 10
	return True

def power(x, a):
	if a == 0:
		return 1
	z = power(x, a // 2)
	z = z ** 2 % mod
	if a % 2:
		z = z * x % mod
	return z
fact = [1 for _ in range(N + 1)]
for no in range(2, N + 1):
	fact[no] = fact[no - 1] * no % mod
[a, b, n] = list(map(int, input().split()))
count = 0
val = (n + 1) * b - a
for freq in range(n + 1):
	val += a - b
	if checkgood(val, a, b):
		count += fact[n] * power(fact[freq], mod - 2) % mod * power(fact[n - freq], mod - 2) % mod
		count %= mod
print(count)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List
import functools
import operator as op
MOD = 1000000007
MAXN = 10 ** 6 + 5
factorial = [0 for _ in range(MAXN)]
factorial[0] = 1
for i in range(1, MAXN):
	factorial[i] = factorial[i - 1] * i % MOD

def pow(a, b):
	if b == 0:
		return 1
	c = b // 2
	d = pow(a, c)
	if b % 2 == 0:
		return d * d % MOD
	return d * d * a % MOD

def inverse(k):
	return pow(k, MOD - 2)

def ncr(n, k):
	k = min(k, n - k)
	return factorial[n] * inverse(factorial[k]) % MOD * inverse(factorial[n - k]) % MOD

def dlen(val):
	s = 0
	while val > 0:
		s += 1
		val //= 10
	return s

def gen(index, nbit, pre, a, b):
	if index >= nbit:
		return [pre]
	return gen(index + 1, nbit, pre * 10 + a, a, b) + gen(index + 1, nbit, pre * 10 + b, a, b)

def count(lo, hi, a, b, n, nnum):
	d = b - a
	ans = 0
	for v in gen(0, n, 0, a, b):
		if v < lo or v > hi:
			continue
		u = v - a * nnum
		if u % d == 0:
			y = u // d
			x = nnum - y
			ans += ncr(nnum, x)
			ans %= MOD
	return ans

def solve(N, A, B):
	(lo, hi) = (N * A, N * B)
	(nl, nh) = (dlen(lo), dlen(hi))
	if nl == nh:
		return count(lo, hi, A, B, nl, N)
	else:
		return count(lo, 10 ** nl - 1, A, B, nl, N) + count(10 ** nl, hi, A, B, nh, N)

def test():
	N = 10 ** 6
	A = random.randint(1, 5)
	B = random.randint(1, 4) + A
	t0 = time.time()
	print(solve(N, A, B))
	print(time.time() - t0)
(A, B, N) = map(int, input().split())
print(solve(N, A, B))


fact = [1]
mod = 10 ** 9 + 7

def factorial(n):
	global mod
	global fact
	fact = [1]
	mod = 10 ** 9 + 7
	for i in range(1, n + 1):
		fact.append(fact[-1] * i)
		fact[-1] %= mod

def C(n, k):
	global mod
	return fact[n] * pow(fact[k], mod - 2, mod) % mod * pow(fact[n - k], mod - 2, mod) % mod

def good(x, a, b):
	while x > 0:
		if x % 10 != a and x % 10 != b:
			return False
		x //= 10
	return True
for _ in range(1):
	ans = 0
	(a, b, n) = map(int, input().split())
	factorial(n)
	for i in range(n + 1):
		if good(i * a + (n - i) * b, a, b):
			ans += C(n, i)
			ans %= mod
	print(ans)


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
mod = 10 ** 9 + 7
(a, b, n) = R()
fact = [1] * (n + 1)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i
	fact[i] %= mod

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a, m):
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def check(val, a, b):
	while val > 0:
		if val % 10 != a and val % 10 != b:
			return False
		val //= 10
	return True
ans = 0
for i in range(n + 1):
	if check(a * i + b * (n - i), a, b):
		ans += fact[n] * modinv(fact[i] * fact[n - i] % mod, mod)
		ans %= mod
print(ans)


import sys
from math import gcd, sqrt, ceil, log2
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
import math
sys.setrecursionlimit(2 * 10 ** 5 + 10)
import heapq
from itertools import permutations
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_sum(bit, i):
	s = 0
	i += 1
	while i > 0:
		s += bit[i]
		i -= i & -i
	return s

def update(bit, n, i, v):
	i += 1
	while i <= n:
		bit[i] += v
		i += i & -i

def modInverse(b, m):
	g = math.gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def primeFactors(n):
	sa = set()
	sa.add(n)
	while n % 2 == 0:
		sa.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			sa.add(i)
			n = n // i
	return sa

def seive(n):
	pri = [True] * (n + 1)
	p = 2
	while p * p <= n:
		if pri[p] == True:
			for i in range(p * p, n + 1, p):
				pri[i] = False
		p += 1
	return pri

def check_prim(n):
	if n < 0:
		return False
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def getZarr(string, z):
	n = len(string)
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and string[r - l] == string[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and string[r - l] == string[r]:
					r += 1
				z[i] = r - l
				r -= 1

def search(text, pattern):
	concat = pattern + '$' + text
	l = len(concat)
	z = [0] * l
	getZarr(concat, z)
	ha = []
	for i in range(l):
		if z[i] == len(pattern):
			ha.append(i - len(pattern) - 1)
	return ha

def mergeIntervals(arr):
	arr.sort(key=lambda x: x[0])
	m = []
	s = -10000
	max = -100000
	for i in range(len(arr)):
		a = arr[i]
		if a[0] > max:
			if i != 0:
				m.append([s, max])
			max = a[1]
			s = a[0]
		elif a[1] >= max:
			max = a[1]
	if max != -100000 and [s, max] not in m:
		m.append([s, max])
	return m

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def sol(n):
	seti = set()
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			seti.add(n // i)
			seti.add(i)
	return seti

def lcm(a, b):
	return a * b // gcd(a, b)
(a, b, n) = map(int, input().split())
mod = 10 ** 9 + 7
x = 0
y = n
ans = 0
fac = [1]
for i in range(1, n + 100):
	fac.append(fac[i - 1] * i % mod)
while x <= n:
	z = y * b + x * a
	flag = 0
	for i in str(z):
		if int(i) != a and int(i) != b:
			flag = 1
			break
	if not flag:
		z1 = modInverse(fac[x] * fac[y], mod)
		ans += fac[n] * z1 % mod
		ans %= mod
	y -= 1
	x += 1
print(ans % mod)


MOD = 10 ** 9 + 7
p = 1000009
fact = [0] * p
fact[0] = 1
for i in range(1, p):
	fact[i] = fact[i - 1] * i % MOD

def MI(a, MOD):
	return pow(a, MOD - 2, MOD)

def ncr(n, k, MOD):
	if n == k or k == 0:
		return 1
	if n < k:
		return 0
	return fact[n] * MI(fact[k], MOD) % MOD * MI(fact[n - k], MOD) % MOD % MOD
(a, b, n) = map(int, input().split())
good = [a, b]
j = -1
for i in range(10 ** 5):
	j += 1
	good.append(good[j] * 10 + a)
	good.append(good[j] * 10 + b)
good.sort()
good = [i for i in good if n * min(a, b) <= i <= n * max(a, b)]
ans = 0
MOD = 10 ** 9 + 7
for x in range(0, n + 1):
	if a * x + b * (n - x) in good:
		ans += ncr(n, x, MOD)
		ans %= MOD
print(ans)


(a, b, n) = list(map(int, input().split()))
m = 1000000007
fact = [1]
for i in range(1, n + 1):
	fact.append(fact[-1] * i % m)
ans = 0
for i in range(n + 1):
	su = a * i + b * (n - i)
	coef = 1
	while su > 0:
		if su % 10 != a and su % 10 != b:
			coef = 0
		su //= 10
	if coef:
		ans += fact[n] * pow(fact[i] * fact[n - i], m - 2, m)
		ans = ans % m
print(ans % m)


(a, b, n) = list(map(int, input().split()))

def ok(s):
	while s:
		if s % 10 != a and s % 10 != b:
			return False
		s = int(s / 10)
	return True
ans = 0
p = int(1000000000.0 + 7)
A = [1]
for i in range(1, n + 1):
	A.append(int(i * A[i - 1] % p))
for x in range(0, n + 1):
	y = n - x
	if ok(a * x + b * y):
		ans += A[n] * pow(A[x], p - 2, p) % p * pow(A[y], p - 2, p) % p
		ans %= p
print(int(ans))


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from collections import defaultdict as dd, deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))
mod = int(1000000000.0 + 7)

def check(k):
	while k > 0:
		x = k % 10
		k //= 10
		if x != a and x != b:
			return False
	return True

def fac(n):
	f = [0] * (n + 1)
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % mod
	return f
(a, b, n) = mdata()
ans = 0
f = fac(n)
for i in range(n + 1):
	k = a * i + b * (n - i)
	if check(k):
		ans = (ans + int(pow(f[i] * f[n - i], mod - 2, mod))) % mod
print(ans * f[n] % mod)


def egcd(a, b):
	if b == 0:
		return (a, 1, 0)
	(g, x1, y1) = egcd(b, a % b)
	x = y1
	y = x1 - y1 * (a // b)
	return (g, x, y)

def mod_inv(a, b):
	return (egcd(a, b)[1] % b + b) % b

def gud(a, b, x):
	a = str(a)
	b = str(b)
	x = set(str(x))
	if len(x) > 2:
		return False
	elif len(x) == 2:
		if a in x and b in x:
			return True
		else:
			return False
	elif a in x or b in x:
		return True
	else:
		return False
(a, b, n) = map(int, input().split())
d = {0: 1}
m = 10 ** 9 + 7
for i in range(1, n + 1):
	d[i] = d[i - 1] * i % m
ans = 0
for i in range(n + 1):
	x = a * i + b * (n - i)
	if gud(a, b, x):
		ans += d[n] % m * mod_inv(d[i], m) * mod_inv(d[n - i], m) % m
print(ans % m)


import math
from sys import stdin
I = stdin.readline
mod = 1000000007
fact = [1 for i in range(1000000 + 5)]
for i in range(2, len(fact)):
	fact[i] = fact[i - 1] * i
	fact[i] %= mod
(a, b, n) = map(int, I().split())
c1 = chr(a + ord('0'))
c2 = chr(b + ord('0'))
ans = 0
for x in range(0, n + 1):
	now = a * x + n * b - b * x
	flag = False
	for c in str(now):
		if c != c1 and c != c2:
			flag = True
			break
	if not flag:
		now = fact[n]
		y = fact[x]
		z = fact[n - x]
		asd = pow(y * z, mod - 2, mod)
		now *= asd
		now %= mod
		ans += now
		ans %= mod
print(int(ans))


def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a, m):
	(g, x, y) = egcd(a, m)
	return x % m
(a, b, n) = map(int, input().split())
c = str(a) + str(b)
(f, mod, ans) = ([1], 1000000007, 0)
for i in range(1, n + 1):
	f.append(f[-1] * i % mod)
s = a * n
for i in range(n + 1):
	if all((i in c for i in str(s))):
		ans += f[n] * modinv(f[i] * f[n - i], mod) % mod
	s += b - a
print(ans % mod)


z = 1000000007

def modinv(p, q):
	res = 1
	while q:
		if q % 2:
			res = res * p % z
			q -= 1
		else:
			p = p * p % z
			q //= 2
	return res
(a, b, n) = map(int, input().split())
times = n
s = 0
arr = [1] * (n + 1)
p = 1
for i in range(1, n + 1):
	p = p * i % z
	arr[i] = p
while times > -1:
	x = str(a * times + b * (n - times))
	counta = countb = l = 0
	for i in x:
		if i == str(a):
			counta += 1
		elif i == str(b):
			countb += 1
		l += 1
	if counta + countb == l:
		s = (s + arr[-1] * modinv(arr[times] * arr[n - times] % z, z - 2)) % z
	times -= 1
print(s)


MOD = 1000000007
MX = 1000000
fact = [1] * (MX + 1)
for i in range(1, MX + 1):
	fact[i] = fact[i - 1] * i % MOD

def power(a, b):
	res = 1
	while b > 0:
		if b % 2 == 1:
			res = res * a % MOD
		a = a * a % MOD
		b //= 2
	return res

def inv(n):
	return power(n, MOD - 2)

def choose(n, k):
	return fact[n] * inv(fact[n - k]) * inv(fact[k])

def is_good(n, g):
	while n > 0:
		if n % 10 not in g:
			return False
		n //= 10
	return True
(a, b, n) = map(int, input().split())
res = 0
for ca in range(n + 1):
	cb = n - ca
	if is_good(ca * a + cb * b, [a, b]):
		res += choose(n, ca)
		res %= MOD
print(res)


from math import factorial as fct
MOD = 10 ** 9 + 7

def c(n, k):
	return fct(n) // (fct(k) * fct(n - k))

def check(val, a, b):
	while val > 0:
		if val % 10 == a or val % 10 == b:
			val = val // 10
		else:
			return False
	return True
(a, b, n) = map(int, input().split())
f = [1]
for i in range(1, n + 1):
	f.append(f[-1] * i % MOD)
ans = 0
for i in range(n + 1):
	if check(i * a + (n - i) * b, a, b):
		ans += pow(f[i] * f[n - i], MOD - 2, MOD)
		ans %= MOD
print(ans * f[n] % MOD)


MOD = int(1000000000.0 + 7)
fact = [1]
for i in range(1, int(1000000.0) + 1, 1):
	fact.append(fact[i - 1] * i % MOD)
(A, B, N) = list(map(int, input().split()))
ans = 0
for i in range(N + 1):
	f = A * i + B * (N - i)
	ng = False
	while f:
		t = f % 10
		if t != A and t != B:
			ng = True
			break
		f //= 10
	if ng:
		continue
	ans = (ans + fact[N] * pow(fact[i], MOD - 2, MOD) * pow(fact[N - i], MOD - 2, MOD)) % MOD
print(ans)


fact = [1] * 1000007
for i in range(1, 1000007):
	fact[i] = i * fact[i - 1] % 1000000007

def nCr(n, r):
	a = fact[n]
	b = fact[r] * fact[n - r] % 1000000007
	c = pow(b, 1000000005, 1000000007)
	return a * c % 1000000007
count = 0
(a, b, n) = map(int, input().split())
for i in range(n + 1):
	s = a * i + b * (n - i)
	if str(s).replace(str(a), '').replace(str(b), '') == '':
		count = (count + nCr(n, i)) % 1000000007
print(count)


import os
import sys
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def good(n):
	n = str(n)
	for i in n:
		if int(i) not in (A, B):
			return False
	return True
(A, B, N) = value()
ans = 0
fact = [1]
for i in range(1, N + 1):
	fact.append(fact[-1] * i % M)
for a in range(N + 1):
	b = N - a
	if good(a * A + b * B):
		here = pow(fact[a] * fact[b], M - 2, M)
		ans = (ans + fact[N] * here % M) % M
print(ans)


f = [0] * (10 ** 6 + 1)
f[0] = f[1] = 1
mod = 10 ** 9 + 7
for i in range(2, 10 ** 6 + 1):
	f[i] = f[i - 1] * i % mod

def comb(n, r):
	return f[n] * pow(f[n - r] * f[r], mod - 2, mod) % mod
(a, b, n) = map(int, input().split())
ans = 0

def is_good(x, a, b):
	x = str(x)
	a = str(a)
	b = str(b)
	flag = True
	for xx in x:
		if xx != a and xx != b:
			flag = False
	return flag
for k in range(n + 1):
	s = a * k + b * (n - k)
	if is_good(s, a, b):
		ans += comb(n, k)
		ans %= mod
print(ans % mod)


(a, b, n) = map(int, input().split())
dic = {0: 1}
m = 10 ** 9 + 7
for i in range(1, n + 1):
	dic[i] = dic[i - 1] * i % m

def modExp(a, n, m=10 ** 9 + 7):
	if n == 0:
		return 1
	elif n == 1:
		return a
	else:
		while n >= 2:
			if n % 2 == 0:
				n = n // 2
				return modExp(a % m * (a % m) % m, n, m)
			else:
				n = (n - 1) // 2
				return a % m * modExp(a % m * (a % m) % m, n, m) % m % m

def nCr(n, r):
	return dic[n] * modExp(dic[n - r], m - 2) * modExp(dic[r], m - 2) % m
out = 0
for i in range(n + 1):
	op = str(a * i + b * (n - i))
	for j in op:
		if j != str(a) and j != str(b):
			break
	else:
		out += nCr(n, i)
		out = out % m
print(out)


def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
(a, b, n) = map(int, input().split())
ans = 0
m = 1000000007
fct = [1] * (n + 1)
fct[0] = 1
for i in range(1, n + 1):
	fct[i] = fct[i - 1] * i % m
for i in range(n + 1):
	k = i * a + (n - i) * b
	k = str(k)
	ch1 = str(a)
	ch2 = str(b)
	a1 = k.count(ch2)
	a2 = k.count(ch1)
	if a1 + a2 == len(k):
		g = fct[n]
		j = power(fct[i], m - 2, m) % m
		j = (j * power(fct[n - i], m - 2, m) + m) % m
		j = (g * j + m) % m
		j = (j + m) % m
		ans = (ans + j) % m
		ans = (ans + m) % m
print(ans)


(a, b, n) = [int(x) for x in input().split()]
m = 1000000007
fact = [1]

def helper(a, b, n):
	while n:
		curr = n % 10
		if curr != a and curr != b:
			return False
		n = n // 10
	return True
for i in range(1, n + 1):
	fact.append(fact[-1] * i % m)
s = b * n
ans = 0
for i in range(n + 1):
	if helper(a, b, s):
		ans += fact[n] * pow(fact[i] * fact[n - i], m - 2, m)
		ans %= m
	s -= b
	s += a
print(ans % (10 ** 9 + 7))


import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(sys.stdin.readline())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def power(a, b, mod):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % mod
		a = a * a % mod
		b = b // 2
	return res

def factorial(fact, n, mod):
	for i in range(1, n + 1):
		fact[i] = i % mod * fact[i - 1] % mod % mod

def ncr(fact, n, r, mod):
	if r > n | n < 0 | r < 0:
		return 0
	return fact[n] % mod * (power(fact[r], mod - 2, mod) % mod) * (power(fact[n - r], mod - 2, mod) % mod) % mod

def Solution(a, b, n, fact, mod):
	res = 0
	for i in range(n + 1):
		t = a * i + (n - i) * b
		flag = False
		while t > 0:
			if t % 10 != a and t % 10 != b:
				flag = True
				break
			t = t // 10
		if flag:
			continue
		res = (res % mod + ncr(fact, n, i, mod) % mod) % mod
	print(res)

def main():
	mod = 1000000007
	(a, b, n) = get_ints_in_variables()
	fact = [1 for _ in range(n + 1)]
	factorial(fact, n, mod)
	Solution(a, b, n, fact, mod)
main()


MOD = 10 ** 9 + 7
(a, b, n) = list(map(int, input().strip().split(' ')))

def check(a, b, x):
	temp = x % 10
	if temp != a and temp != b:
		return 0
	while x > 0:
		temp = x % 10
		if temp != a and temp != b:
			return 0
		x = x // 10
	return 1
fact = [1]
infact = [1]
temp = 1
intemp = 1
for i in range(1, n + 1):
	temp *= i
	temp %= MOD
	fact += [temp]

def binom(a, b):
	MOD = 10 ** 9 + 7
	if b == 0:
		return 1
	else:
		temp = pow(fact[a - b] * fact[b], MOD - 2, MOD) * fact[a]
		return temp % MOD
total = 0
for i in range(n + 1):
	temp = i * a + (n - i) * b
	if check(a, b, temp) == 1:
		total += binom(n, i)
		total %= MOD
print(total % MOD)


from math import factorial
MOD = 10 ** 9 + 7
fact = {}
(a, b, n) = map(int, input().split())
fact[0] = 1
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i % MOD
ans = 0
for (i, j) in zip(range(n + 1), range(n, -1, -1)):
	if set(str(a * i + b * j)) <= {f'{a}', f'{b}'}:
		ans += fact[n] * pow(fact[n - i] * fact[i] % MOD, MOD - 2, MOD) % MOD
print(ans % MOD)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()

def is_beautiful(sum):
	if sum == 0:
		return 0
	while sum:
		if sum % 10 != a:
			if sum % 10 != b:
				return 0
		sum //= 10
	return 1

def nCr(n, r):
	return fact[n] * invfact[r] * invfact[n - r] % mod
fact = [0] * 1000005
invfact = [0] * 1000005
fact[0] = fact[1] = invfact[0] = invfact[1] = 1
for i in range(1, 1000003):
	fact[i] = fact[i - 1] % mod * i % mod % mod
invfact[1000000] = pow(fact[1000000], mod - 2, mod)
for i in range(999999, 0, -1):
	invfact[i] = invfact[i + 1] % mod * (i + 1) % mod % mod
(a, b, n) = get_ints()
if a == b:
	if is_beautiful(a * n):
		print(1)
	else:
		print(0)
ans = 0
for i in range(n + 1):
	if is_beautiful(a * i + b * (n - i)):
		ans += nCr(n, i)
ans %= mod
print(ans)


def read():
	return list(map(int, input().strip().split(' ')))
MOD = 10 ** 9 + 7

def fact():
	N = 10 ** 6 + 1
	facto = [0] * (N + 1)
	facto[0] = 1
	for i in range(1, N + 1):
		facto[i] = facto[i - 1] % MOD * i % MOD
	return facto
facto = fact()

def chk(n, a, b):
	s = 0
	while n > 0:
		if not n % 10 in (a, b):
			return False
		n //= 10
	return True

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

def solve():
	(a, b, n) = read()
	ans = 0
	for i in range(n + 1):
		(x, y) = (i, n - i)
		if chk(a * x + b * y, a, b):
			u = facto[n]
			d = modInverse(facto[x] % MOD * (facto[y] % MOD) % MOD, MOD)
			ans += u * d % MOD
			ans %= MOD
	print(ans)
solve()


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
m = 1000000007

def fastpower_with_mod(x, y, m):
	res = 1
	if x == 0:
		return 0
	x %= m
	while y > 0:
		if y % 2 != 0:
			res = res * x % m
		x = x * x % m
		y //= 2
	return res

def check_sum(sm, a, b):
	while sm:
		if sm % 10 != a and sm % 10 != b:
			return False
		sm //= 10
	return True

def calc_inv(num, m):
	return fastpower_with_mod(num, m - 2, m)

def ncr(n, r, m):
	if n == r or r == 0:
		return 1
	if n < r:
		return 0
	return fac[n] * calc_inv(fac[r], m) % m * calc_inv(fac[n - r], m) % m % m
(a, b, n) = MAP()
fac = [0] * (10 ** 6 + 9)
fac[1] = 1
for i in range(2, n + 1):
	fac[i] = fac[i - 1] * i % m
res = 0
for i in range(n + 1):
	sm = a * i + b * (n - i)
	if check_sum(sm, a, b):
		res += ncr(n, i, m)
		res %= m
print(res)


fact = {}
modulo = 1000000007

def check(val, a, b):
	while val:
		if val % 10 == a or val % 10 == b:
			val //= 10
		else:
			return False
	return True

def modpow(base, exp, mod):
	if exp == 0:
		return 1
	if exp & 1:
		return modpow(base, exp - 1, mod) * base % mod
	res = modpow(base, exp >> 1, mod)
	return res * res % mod

def getC(n, i):
	res = fact[n]
	div = fact[n - i] * fact[i]
	div %= modulo
	div = modpow(div, modulo - 2, modulo)
	return res * div % modulo
(a, b, n) = [int(x) for x in input().split()]
fact[0] = 1
for i in range(1, 1000005):
	fact[i] = fact[i - 1] * i
	fact[i] %= modulo
ans = 0
for i in range(n + 1):
	expsum = a * i + b * (n - i)
	if check(expsum, a, b):
		ans += getC(n, i)
		ans %= modulo
print(ans)


def check(x):
	while x:
		if x % 10 != a and x % 10 != b:
			return False
		x //= 10
	return True
(a, b, n) = map(int, input().split())
(factorial, ans) = ([1], 0)
for i in range(1, n + 1):
	factorial.append(factorial[-1] * i % 1000000007)
for i in range(n + 1):
	if check(a * i + b * (n - i)):
		ans += factorial[n] * pow(factorial[i] * factorial[n - i], 1000000005, 1000000007)
		ans %= 1000000007
print(ans % 1000000007)


(a, b, n) = map(int, input().split())
import sys
input = sys.stdin.readline
p = 10 ** 9 + 7
pri = p
fac = [1 for i in range(10 ** 6 + 1)]
for i in range(2, len(fac)):
	fac[i] = fac[i - 1] * (i % pri) % pri

def modi(x):
	return pow(x, p - 2, p) % p

def ncr(n, r):
	x = fac[n] * (modi(fac[r]) % p * (modi(fac[n - r]) % p)) % p % p
	return x
ans = []
for i in range(n + 1):
	total = i * a + (n - i) * b
	s = str(total)
	if s.count(str(a)) + s.count(str(b)) == len(s):
		ans.append([i, n - i])
total = 0
for i in range(len(ans)):
	total += ncr(n, ans[i][0])
	total %= pri
print(total)


mod = 1000000007
fact = []

def Beautiful_Numbers(a, b, n):
	result = 0
	Factorial(n)
	comb = []
	if n == 1:
		return 2
	for m in range(0, n + 1):
		x = m * a + (n - m) * b
		if Es_Bueno(x, a, b):
			if m <= n // 2:
				c = Combinaciones(n, m)
				comb.append(c)
				result += c
				result %= mod
			elif comb[n - m] != -1:
				result += comb[n - m]
				result %= mod
			else:
				c = Combinaciones(n, m)
				comb[n - m] = c
				result += c
				result %= mod
		else:
			comb.append(-1)
	return result

def Combinaciones(n, m):
	if m == 0 | m == n:
		return 1
	else:
		tmp = fact[n - m] * fact[m] % mod
		tmp = binpow(tmp, mod - 2, mod)
		return fact[n] * tmp % mod

def binpow(d, deg, mod):
	if not deg:
		return 1 % mod
	if deg & 1:
		return binpow(d, deg - 1, mod) * d % mod
	res = binpow(d, deg >> 1, mod)
	return res * res % mod

def Factorial(n):
	fact.append(1)
	for i in range(1, n + 1):
		fact.append(fact[i - 1] * i % mod)

def Es_Bueno(x, a, b):
	x_str = str(x)
	for i in range(0, len(x_str)):
		if x_str[i] != str(a) and x_str[i] != str(b):
			return False
	return True
_input = [int(x) for x in input().split()]
a = _input[0]
b = _input[1]
n = _input[2]
print(Beautiful_Numbers(a, b, n))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase

def main():

	def getFactorialsUpTo(number):
		fact = [0] * (number + 1)
		fact[0] = 1
		for num in range(1, number + 1):
			fact[num] = num * fact[num - 1] % mod
		return fact

	def isGood(number):
		while number > 0:
			lastDigit = number % 10
			if lastDigit != a and lastDigit != b:
				return False
			number //= 10
		return True
	(a, b, n) = [int(x) for x in input().split()]
	mod = 1000000007
	fact = getFactorialsUpTo(n)
	numOfExcellent = 0
	for numOfA in range(n + 1):
		numOfB = n - numOfA
		total = numOfA * a + numOfB * b
		if isGood(total):
			divisor = fact[numOfA] * fact[numOfB] % mod
			divisor = pow(divisor, mod - 2, mod)
			numOfExcellent += fact[n] * divisor % mod
			numOfExcellent %= mod
	print(numOfExcellent)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
input = lambda : sys.stdin.readline().rstrip('\r\n')

def print(*args, **kwargs):
	sep = kwargs.pop('sep', ' ')
	file = kwargs.pop('file', sys.stdout)
	atStart = True
	for x in args:
		if not atStart:
			file.write(sep)
		file.write(str(x))
		atStart = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
main()


import io
mod = 1000000007

def power(x, e):
	if e == 1:
		return x % mod
	tmp = power(x, e // 2)
	tmp = tmp % mod * (tmp % mod) % mod
	if e % 2 != 0:
		tmp = tmp % mod * (x % mod) % mod
	return tmp

class Solution:

	def __init__(self, n):
		fact = list(range(n + 1))
		(fact[0], fact[1]) = (1, 1)
		for i in range(2, n + 1):
			fact[i] = fact[i - 1] * i
			fact[i] %= mod
		self.fact = fact

	def rCn(self, p, n):
		tmp = power(self.fact[n - p] * self.fact[p], mod - 2)
		return tmp % mod * (self.fact[n] % mod) % mod

	def is_good(self, x, a, b):
		s = str(x)
		return s.count(str(a)) + s.count(str(b)) == len(s)

	def solve(self, a, b, n):
		ans = 0
		for p in range(n + 1):
			if self.is_good(p * a + (n - p) * b, a, b):
				ans += self.rCn(p, n)
				ans %= mod
		return ans
out = io.StringIO()
(a, b, n) = map(int, input().split())
sol = Solution(n)
print(sol.solve(a, b, n))


M = 1000000007
import sys

def alele():
	return list(map(int, sys.stdin.readline().strip().split()))

def ilele():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(a, b, n) = ilele()
Ans = 0
fact = [1] * (n + 1)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i % M
for i in range(n + 1):
	s = str(a * i + b * (n - i))
	Noa = 0
	Nob = 0
	for j in s:
		if int(j) == a:
			Noa += 1
		elif int(j) == b:
			Nob += 1
	if Noa + Nob == len(s):
		Ans = (Ans + pow(fact[n - i] * fact[i], M - 2, M)) % M
print(Ans * fact[n] % M)


import sys
import math
import collections
import heapq
import decimal
input = sys.stdin.readline
(a, b, n) = (int(i) for i in input().split())
mod = 1000000007
f = [1]
for i in range(1, 1000001):
	f.append(f[i - 1] * i % mod)
s1 = 0
for i in range(n + 1):
	s = str(a * i + b * (n - i))
	c = 1
	for j in s:
		if j != str(a) and j != str(b):
			c = 0
			break
	if c == 1:
		k = f[n] * pow(f[i] * f[n - i], mod - 2, mod) % mod
		s1 = (s1 + k) % mod
print(s1)


N = 1000007
m = int(1000000000.0 + 7)
sum = 0
ans = 0
fact = [0 for i in range(0, 1000007)]

def modularexponentiation(a: int, b: int, m: int):
	res = 1
	a = a % m
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b // 2
	return res

def modinverse(a: int, m: int):
	return modularexponentiation(a, m - 2, m)
(a, b, n) = [int(x) for x in input().split()]
fact[0] = 1
for i in range(1, N):
	fact[i] = fact[i - 1] * i % m
for i in range(0, n + 1):
	sum = a * i + b * (n - i)
	while sum > 0:
		if sum % 10 != a and sum % 10 != b:
			break
		sum = sum // 10
	if sum == 0:
		ans = (ans + fact[n] * modinverse(fact[i] * fact[n - i] % m, m)) % m
print(ans)


mxn = 10 ** 6 + 10
fact = [1] * mxn
mod = 10 ** 9 + 7
for i in range(1, mxn):
	fact[i] = fact[i - 1] * i % mod

def nck(n, k):
	return fact[n] * pow(fact[k] * fact[n - k], mod - 2, mod) % mod

def log(n):
	ans = 0
	while n:
		ans += 1
		n //= 10
	return ans
(a, b, n) = map(int, input().split())
if a < b:
	(a, b) = (b, a)
mn = b * n
mx = a * n
leng = [i for i in range(log(mn), log(mx) + 1)]
ans = 0

def check(num):
	mx = n * a
	if (mx - num) % (a - b) != 0:
		return 0
	l = n - (mx - num) // (a - b)
	r = n - l
	return nck(n, l) * nck(n - l, r)
for l in leng:
	for mask in range(1 << l):
		num = 0
		mul = 1
		for bit in range(l):
			if mask & 1 << bit:
				num += mul * a
			else:
				num += mul * b
			mul *= 10
		if mn <= num and num <= mx:
			ans += check(num)
			ans %= mod
print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	mod = 10 ** 9 + 7
	(a, b, n) = map(int, input().split())
	(f, invfac) = ([1], [1])
	for i in range(1, n + 1):
		f.append(f[-1] * i % mod)
		invfac.append(i + 1)
	invfac[-1] = pow(f[-1], mod - 2, mod)
	for i in range(n - 1, -1, -1):
		invfac[i] *= invfac[i + 1]
		invfac[i] %= mod
	ans = 0
	for i in range(n + 1):
		z = str((n - i) * b + i * a)
		if z.count(str(a)) + z.count(str(b)) == len(z):
			ans = (ans + f[n] * invfac[n - i] * invfac[i]) % mod
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


MOD = int(1000000000.0 + 7)

def fast_power(b, e):
	res = 1
	while e > 0:
		if e % 2 == 1:
			res = res * b % MOD
		b = b * b % MOD
		e //= 2
	return res
(a, b, n) = map(int, input().split())
(s, res) = (set(), 0)
for x in range(2, 1 << 8):
	z = 0
	while x > 1:
		z = z * 10 + (a, b)[x & 1]
		x >>= 1
	s.add(z)
fact = [1] * (n + 1)
for i in range(1, n + 1):
	fact[i] = fact[i - 1] * i % MOD
for x in range(n + 1):
	if x * a + (n - x) * b in s:
		res = (res + fast_power(fact[x] * fact[n - x], MOD - 2)) % MOD
print(res * fact[n] % MOD)