CodeForces 300C Beautiful Numbers
枚举,组合数,逆元。
枚举$a$用了$i$个,那么$b$就用了$n-i$个,这个时候和$sum=a*i+b*(n-i)$,判断$sum$是否满足条件,如果满足,那么答案加上$C(n,i)$。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std; int n;
long long a,b;
long long mod=1e9+;
long long ans;
long long f[]; bool check(int x)
{
long long num=(long long)x*a
+(long long)(n-x)*b;
while(num)
{
if(num%!=a&&num%!=b) return ;
num=num/;
}
return ;
} long long extend_gcd(long long a,long long b,long long &x,long long &y)
{
if(a==&&b==) return -;
if(b==){x=;y=;return a;}
long long d=extend_gcd(b,a%b,y,x);
y-=a/b*x;
return d;
} long long mod_reverse(long long a,long long n)
{
long long x,y;
long long d=extend_gcd(a,n,x,y);
if(d==) return (x%n+n)%n;
else return -;
} long long C(int a,int b)
{
return f[a]*mod_reverse(f[b]*f[a-b],mod)%mod;
} int main()
{
f[]=;
for(long long i=;i<=;i++) f[i]=i*f[i-]%mod;
scanf("%lld%lld%d",&a,&b,&n);
ans=;
for(int i=;i<=n;i++)
{
if(check(i)) ans=(ans+C(n,i))%mod;
}
printf("%lld\n",ans);
return ;
}
CodeForces 300C Beautiful Numbers的更多相关文章
- CodeForces 300C Beautiful Numbers(乘法逆元/费马小定理+组合数公式+高速幂)
C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 300C Beautiful Numbers 【组合数】+【逆元】
<题目链接> 题目大意: 给出a和b,如果一个数每一位都是a或b,那么我们称这个数为good,在good的基础上,如果这个数的每一位之和也是good,那么这个数是excellent.求长度 ...
- [CodeForces 300C Beautiful Numbers]组合计数
题意:十进制的每一位仅由a和b组成的数是“X数”,求长度为n,各数位上的数的和是X数的X数的个数 思路:由于总的位数为n,每一位只能是a或b,令a有p个,则b有(n-p)个,如果 a*p+b*(n-p ...
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...
- Codeforces 55D. Beautiful numbers(数位DP,离散化)
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- CodeForces 55D Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- CodeForces - 55D Beautiful numbers —— 数位DP
题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...
- CodeForces - 55D - Beautiful numbers(数位DP,离散化)
链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...
随机推荐
- Retrofit相关资料
高速Android开发系列网络篇之Retrofithttp://www.w3c.com.cn/%E5%BF%AB%E9%80%9Fandroid%E5%BC%80%E5%8F%91%E7%B3%BB% ...
- HDOJ 5063 Operation the Sequence
注意到查询次数不超过50次,那么能够从查询位置逆回去操作,就能够发现它在最初序列的位置,再逆回去就可以求得当前查询的值,对于一组数据复杂度约为O(50*n). Operation the Sequen ...
- Scala Web 框架——Lift(一)准备工作
[Lift]Scala Web 框架——Lift(一)准备工作 Lift 官方网站:http://liftweb.net/ 下载 http://liftweb.net/download 下载.zip压 ...
- .NET MVC4 实训记录之二(扩展WebSecurity模型下的UserProfile表)
使用VS2013创建MVC4项目后,自动生成的代码中默认使用WebSecurity模型创建用户管理,生成以下数据库:
- EF4.0、4.3创建表达式树状动态查询总结
---------------------------------------------快速适用 效果: where name like '%王%' and Age>=35 or Age< ...
- Visual Studio 2014
开发 ASP.NET vNext 初步总结(使用Visual Studio 2014 CTP1) 2014-06-06 18:04 by 梁逸晨, 2149 阅读, 29 评论, 收藏, 编辑 新特性 ...
- ASP.NET MVC5 视图预编译
ASP.NET MVC5 视图预编译 ASP.NET MVC5 视图预编译 关于Razor视图及引擎原理,就不多说了. 这里通俗或者不恰当地说,cshtml视图文件是先编译成dll文件,再通过视图 ...
- Markdown的使用
原文:http://wowubuntu.com/markdown/ git:https://gitcafe.com/riku/Markdown-Syntax-CN/ 记录一下Markdown的使用,I ...
- Plan : 破晓
题记 : 不要因为走的太远而忘记自己为什么而出发. 1. 白书(算法竞赛入门经典)看完(每一句话都要读懂) 2. 每次听完课把当天内容复习完(自习室10点以后复习) 3. 微机实验要提前预习(把实验报 ...
- Android系统源码导入到eclipse
1.把eclipse工程配置文件复制到android源码根目录下 cp development/ide/eclipse/.classpath ./ 2. 在android源码根目录下新建文 ...