CodeForces 300C 最短路

A

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 300C

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, number111 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: abn(1 ≤ a < b ≤ 9, 1 ≤ n ≤ 106).

Output

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

Sample Input

Input

1 3 3

Output

1

Input

2 3 10

Output

165
时间: 2024-08-06 11:41:33

CodeForces 300C 最短路的相关文章

CodeForces 300C --数论

A - A Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 300C Description Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the deci

Problem B Codeforces 295B 最短路(floyd)

Description Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists

CodeForces 300C Beautiful Numbers(乘法逆元/费马小定理+组合数公式+快速幂)

C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal

Codeforces 300C Beautiful Numbers 【组合数】+【逆元】

<题目链接> 题目大意: 给出a和b,如果一个数每一位都是a或b,那么我们称这个数为good,在good的基础上,如果这个数的每一位之和也是good,那么这个数是excellent.求长度为n的excellent数的个数mod(1e9+7). 解题分析: 我们可以枚举a的个数m,所以b的个数为(n-m),然后判断这种情况是否可行,即,是否满足a*m+b*(n-m)为good number ,如果满足的话,则答案加上C(n,m).因为n很大,并且在计算组合数的过程中,需要除以很大的数,所以需要求

cumt周练题解

cumt2017春季--周练(一) A.CodeForces - 785A 1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n; 6 cin >> n; 7 map<string, int>ma; 8 ma["Tetrahedron"] = 4; 9 ma["Cube"] = 6; 10 ma["Octahedron&quo

CSU-ACM暑假集训基础组七夕专场

•Problem A Codeforces 20C       最短路(dij,spfa) •题意:给出一张n个点m条边的无向图 (2 ≤ n ≤ 105, 0 ≤ m ≤ 105),输出从1到n的任意一条最短路径. •解法:dijkstra或者spfa,用pre数组记录到达每个点最短距离的前驱结点. •注意:路径的长度范围是 1 ≤ wi ≤ 106,从1到n的最短路径长度可能超出int范围. •没有路径从1到达n时要输出-1 1 #include <cstdio> 2 #include &

ACM学习历程—CodeForces 601A The Two Routes(最短路)

题目链接:http://codeforces.com/problemset/problem/601/A 题目大意是有铁路和陆路两种路,而且两种方式走的交通工具不能在中途相遇. 此外,有铁路的地方肯定没有陆路. 这种情况下就会有一个结论,就是至少有一种交通可以直接1到n. 这样只需要对另一种跑一个最短路就OK了. 代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath&

最短路 Codeforces Round #103 (Div. 2) D. Missile Silos

题目传送门 1 /* 2 最短路: 不仅扫描边,还要扫描点:点有两种情况,一种刚好在中点,即从u,v都一样,那么最后/2 3 还有一种是从u,v不一样,两种的距离都是l 4 模板错了,逗了好久:( 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #include <cmath> 10 #include <vector> 11 #include <q

【最短路】Codeforces 710E Generate a String

题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费B. 题目思路: [动态规划][最短路] [动态规划]: 如果当前x不是2的倍数,那么一定需要单个字符增加或删除,而这个单个操作越靠后答案越优. dp(x)=a+min(dp(x-1),dp(x+1)) 如果当前x是2的倍数,那么有两种情况,一种是通过翻倍的方式获得,一种是通过累加的方式获得.只要比