C. Beautiful Numbers

题目连接:

http://www.codeforces.com/contest/300/problem/C

Description

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 (109 + 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 ≤ 106).

Output

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

Sample Input

1 3 3

Sample Output

1

Hint

题意

给你 a,b,n

问你有多少个长度为n的数中只含有a,b

并且这个数的每一个数位之和的数,也只含有a,b

题解:

直接暴力枚举和就好了,然后check

如果可行的话,他的贡献为C(n,i)

C(n,i)用逆元来做就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
#define maxn 1000005
long long fac[maxn];
int a,b,n;
long long qpow(long long a,long long b)
{
long long ans=1;a%=mod;
for(long long i=b;i;i>>=1,a=a*a%mod)
if(i&1)ans=ans*a%mod;
return ans;
}
long long C(long long n,long long m)
{
if(m>n||m<0)return 0;
long long s1=fac[n],s2=fac[n-m]*fac[m]%mod;
return s1*qpow(s2,mod-2)%mod;
}
int check(long long x)
{
while(x)
{
if(x%10!=a&&x%10!=b)return 0;
x/=10;
}
return 1;
}
int main()
{
fac[0]=1;
for(int i=1;i<maxn;i++)
fac[i]=fac[i-1]*i%mod;
scanf("%d%d%d",&a,&b,&n);
long long ans = 0;
for(int i=0;i<=n;i++)
{
long long num = a*i+b*(n-i);
if(check(num))
ans = (ans+C(n,i))%mod;
}
cout<<ans<<endl;
}

Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力的更多相关文章

  1. Codeforces Round #604 (Div. 2) B. Beautiful Numbers

    链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...

  2. Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)

    题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...

  3. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

  4. Codeforces Round #558 (Div. 2)C(计算几何,排列组合,模拟)

    #include<bits/stdc++.h>using namespace std;typedef struct{ double k,b;}node;node k[1000007];bo ...

  5. 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers

    题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...

  6. Codeforces Round #181 (Div. 2)

    A. Array 模拟. B. Coach 模拟. C. Beautiful Numbers good number的位和最大不超过\(10^7\),那么只要枚举a或b的个数,然后最多循环7次判断位和 ...

  7. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  8. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest

    链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...

  9. Codeforces Round #181 (Div. 2) B. Coach 带权并查集

    B. Coach 题目连接: http://www.codeforces.com/contest/300/problem/A Description A programming coach has n ...

随机推荐

  1. js document对象

    document对象可以通过多种方式获取: 最常见的一种情况是,你在文档的script脚本中直接使用document,这个document代表运行着该脚本的文档.(这个document和window. ...

  2. leetcode:ZigZag Conversion 曲线转换

    Question: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of ...

  3. 50种方法优化SQL Server数据库查询

    查询速度慢的原因很多,常见如下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列导致查询不优化. 4.内存不足 ...

  4. 【Python学习笔记】集合

    概述 集合的一般操作 内建函数进行标准操作集合 数学运算符进行标准操作集合 集合的应用 概述 python的集合(set)是无序不重复元素集,是一种容器.集合(set)中的元素必须是不可变对象,即可用 ...

  5. WebGIS的大众化服务

    WebGIS是Web技术与GIS相结合的产物.WebGIS的真正意义在于,它将GIS从专业应用推向了大众化服务,同时为地理信息共享提供了方便而有效的途径. 一.ESRI大会关于WebGIS的报告 纵观 ...

  6. 徐汉彬:亿级Web系统搭建——单机到分布式集群(转载)

    文章转载自http://www.csdn.net/article/2014-11-06/2822529/1 当一个Web系统从日访问量10万逐步增长到1000万,甚至超过1亿的过程中,Web系统承受的 ...

  7. 集群重启后启动ambari-server访问Web页面无法启动集群解决

    集群重启后启动ambari-server访问Web页面无法启动集群解决 使用ambari部署的集群重新启动后,必须手动重启ambari-server和所有集群主机上的ambari-agent. amb ...

  8. HDU1243:反恐训练营

    题目链接:反恐训练营 题意:本质上是求最大公共子序列,然后加上一个权值 分析:见代码 //公共子序列问题 //dp[i][j]表示前s1的前i个与s的前j个匹配得到的最大公共子序列 #include& ...

  9. shell变量定义

    http://blog.csdn.net/longxibendi/article/details/6125075 set - 读写变量语法:set varName ?value?描述:返回变量varN ...

  10. ControlsFX8.0.2中对话框无法判断是否显示的修改

    在org.controlsfx.dialog.FXDialog.java中加入 public abstract boolean isShowing(); 在org.controlsfx.dialog. ...