-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbdeutifulnumbers.java
More file actions
46 lines (44 loc) · 1.36 KB
/
bdeutifulnumbers.java
File metadata and controls
46 lines (44 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class bdeutifulnumbers {
static long[] fact=new long[1000001];
public static void main(String[] args) throws Exception {
fact[0]=1;
for(int i=1;i<fact.length;i++){
fact[i]=(fact[i-1]*i)%1000000007;
}
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int n=sc.nextInt();
long ans=0;
for(int i=0;i<=n;i++){
int p=a*(n-i)+b*i;
if(check(Integer.toString(p),a,b)){
long temp=fact[n]*(binpow(fact[n-i]*fact[i],1000000007-2,1000000007)%1000000007)%1000000007;
ans=(ans+temp)%1000000007;
}
}
System.out.println(ans);
}
public static boolean check(String str,int a,int b){
char j=Integer.toString(a).charAt(0);
char k=Integer.toString(b).charAt(0);
for(int i=0;i<str.length();i++)if(str.charAt(i)!=j && str.charAt(i)!=k)return false;
return true;
}
static long binpow(long a, long b, long m){
a %= m;
long res = 1;
while (b > 0) {
if ((b&1)==1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
}