首页 > 学院 > 开发设计 > 正文

[Codeforces300C]Beautiful Numbers(数学相关)

2019-11-08 18:26:11
字体:
来源:转载
供稿:网友

题目描述

传送门

题解

刚开始以为很神实际上就是一道sb题

枚举n位数中有i个a,自然有n-i个b 判断是否满足条件 如果满足,就是一个有重复元素的排列问题

代码

#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>using namespace std;#define N 1000005#define LL long long#define Mod 1000000007int a,b,n,sum;LL ans,mul[N];LL fast_pow(LL a,int p){ LL ans=1LL; for (;p;p>>=1,a=a*a%Mod) if (p&1) ans=ans*a%Mod; return ans;}void calc(){ mul[0]=1LL; for (LL i=1;i<=n;++i) mul[i]=mul[i-1]*(LL)i%Mod;}bool check(int x){ while (x) { int now=x%10; if (now!=a&&now!=b) return 0; x/=10; } return 1;}int main(){ scanf("%d%d%d",&a,&b,&n); calc(); for (int i=0;i<=n;++i) { sum=i*a+(n-i)*b; if (!check(sum)) continue; ans=(ans+mul[n]*fast_pow(mul[i],Mod-2)%Mod*fast_pow(mul[n-i],Mod-2)%Mod)%Mod; } PRintf("%I64d/n",ans);}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表