枚举,组合数,逆元。

枚举$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的更多相关文章

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

    C. Beautiful Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

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

    <题目链接> 题目大意: 给出a和b,如果一个数每一位都是a或b,那么我们称这个数为good,在good的基础上,如果这个数的每一位之和也是good,那么这个数是excellent.求长度 ...

  3. [CodeForces 300C Beautiful Numbers]组合计数

    题意:十进制的每一位仅由a和b组成的数是“X数”,求长度为n,各数位上的数的和是X数的X数的个数 思路:由于总的位数为n,每一位只能是a或b,令a有p个,则b有(n-p)个,如果 a*p+b*(n-p ...

  4. CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)

    传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...

  5. Codeforces 55D. Beautiful numbers(数位DP,离散化)

    Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...

  6. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  7. CodeForces 55D Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  8. CodeForces - 55D Beautiful numbers —— 数位DP

    题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...

  9. CodeForces - 55D - Beautiful numbers(数位DP,离散化)

    链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...

随机推荐

  1. 通过改变viewport 实现网站自适应

    var phoneWidth = parseInt(window.screen.width); var phoneScale = phoneWidth/640; var userAgent = nav ...

  2. 如何将C#对象转化为JSON字符串

    System.Web.Extensions.dll中类JavaScriptSerializer可以帮助我们把C#对象转化为JSON字符串. 有一个Person类 public class Person ...

  3. form-validation--表单验证插件

    基于jquery的validationEngine表单验证插件,根据官网提示,该插件支持IE6-8,Chrome浏览器,火狐,Safari,Opera 10,但由于有使用到了css3的阴影和圆角样式, ...

  4. Gitlab,Github与Bitbucket

    这段时间开始做毕设,决定使用git来管理代码和相关的文档. 同时希望有一个远程托管,决定在github.bitbucket,以及我自己搭建的gitlab服务器中间选一个,最终决定使用bitbuckt. ...

  5. 学点c++

    描述现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复:还知道这个长方形的宽和长,编号.长.宽都是整数:现在要求按照一下方式排序(默认排序规则都是从小到大): 1.按照编号从小到大排序 2. ...

  6. oracle实例,数据库,服务器区别

    实例(instance) 实例是一个非固定的,基于内存的基本进程与内存结构.当服务器关闭时,实例就不存在了. 数据库(DataBase) 数据库指固定的,基于磁盘的数据文件,控制文件,日志文件,参数文 ...

  7. IOS UI 第十一篇: UITABLEVIEW

    DIY a tableviewcell :   - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *) ...

  8. Codekart 框架

    [Node.js框架] 为什么要开发 Codekart 框架 两年前,在被php的$符号和字符串处理折磨得半夜骂娘之后,我义无反顾地决定:珍爱生命,远离php. 之后一直在寻找一门“完美的语言”,先后 ...

  9. 实现栈最小元素的min函数

    #include<iostream> #include<stack> using namespace std; class min_stack { public: void p ...

  10. Hive中Bucket的应用

    网友南京-李先森给了他收集的一些资料,如下: Buckets 对指定列计算 hash,根据 hash 值切分数据,目的是为了并行,每一个 Bucket 对应一个文件.如将 user 列分散至 32 个 ...