E - Beautiful Numbers
来源:互联网 发布:mac os 10.6.8升级 编辑:程序博客网 时间:2024/06/05 14:08
Description
Vitaly is a very weird man. He's got two favorite digitsa and b. Vitaly calls a positive integergood, if the decimal representation of this integer only contains digitsa and b. Vitaly calls a good numberexcellent, if the sum of its digits is a good number.
For example, let's say that Vitaly's favourite digits are1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number11 isn't.
Now Vitaly is wondering, how many excellent numbers of length exactlyn are there. As this number can be rather large, he asks you to count the remainder after dividing it by1000000007(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 modulo1000000007(109 + 7).
Sample Input
1 3 3
1
2 3 10
165
题意:
somebody喜欢两个数字a和b,他把各个位上完全由这两个数字组成的数字叫做good number(也可以只有a或只有b组成),要是组成的数字的各位加起来的和也是good number,那么这个由a,b组成的good number就是excellent数,输入三个数a,b,n,分别代表喜欢的数a,b和要组成的数的位数,求最多有多少个符合题意的excellent数?
解法:乘法逆元+二分幂
<span style="font-size:18px;">#include<stdio.h>long long int mod=1000000007;long long int vis[1000010]={1};long long int charge(long long int m,long long int n)//快速二分幂求值{ if(n==0) return 1; long long int t=1; while(n) { if(n%2==1) t=t*m%mod; m=m*m%mod; n/=2; } return t;}int main(){ long long int a,b,n,i,j,sum,t1,t2,ans; while(scanf("%lld%lld%lld",&a,&b,&n)!=EOF) { ans=0; for(i=1;i<=n;i++) vis[i]=vis[i-1]*i%mod;//求1到n的阶乘 for(i=0;i<=n;i++) { j=n-i; sum=a*i+b*j; while(sum) { long long int t=sum%10; if(t!=a&&t!=b) break; sum=sum/10; } if(sum==0)//其实这里还包含了一个乘法逆元的求法 { t1=charge(vis[i],mod-2); t2=charge(vis[n-i],mod-2); ans+=vis[n]*t1%mod*t2%mod; } } printf("%lld\n",ans%mod); } return 0;}</span>
- E - Beautiful Numbers
- E-Beautiful Numbers (对每一位求模)
- Round E APAC Test 2017 Problem B. Beautiful Numbers
- Beautiful Numbers
- Beautiful numbers
- Beautiful Numbers
- Beautiful numbers
- Beautiful numbers
- Problem B. Beautiful Numbers Google APAC 2017 University Test Round E
- Why are numbers beautiful?
- Codeforces_C - Beautiful Numbers
- codeforces Beautiful Numbers
- UVa 11472 - Beautiful Numbers
- codeforces55D Beautiful numbers
- codeforces300C. Beautiful Numbers
- C. Beautiful Numbers
- 数位dp Beautiful numbers
- 数位dp, Beautiful numbers
- 把整数从高位开始逐位分割并输出
- Android广告图片轮播控件,支持无限循环和5种主题,可以灵活设置轮播样式、时间、位置、图片加载框架等!
- 写给VR手游开发小白的教程:(三)UnityVR插件CardboardSDKForUnity解析(二)
- builtin descriptor types
- 晶振电路
- E - Beautiful Numbers
- Android 整合实现简单易用、功能强大的RecyclerView
- ubuntu:查看ubuntu系统的版本信息
- 高精度-10106 product
- USB库STM32F0x2移植到STM32F070笔记
- java中8种基本数据类型、基本数据类型的转换与运算符
- Android记忆之我的开始
- iOS开发-底层篇-Class详解
- printf输出问题和c语言求3,5,7整除的数的问题