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 ...
随机推荐
- WTIR Updating Page
NO REPLY. ############### #14090704# ###############
- 用Inno Setup制作WEB程序安装包
原文 用Inno Setup制作WEB程序安装包 最近做了一个WEB程序的安装包,我把制作的过程做个介绍,贴出源码给大家做个参考 看看inno 的脚本 [Setup] AppCopyright=tes ...
- HTML5表单提示placeholder属性兼容IE
placeholder 属性提供可描述输入字段预期值的提示信息(hint). 该提示会在输入字段为空时显示,并会在字段获得焦点时消失. 注释:placeholder 属性适用于以下的 <inpu ...
- 如何优雅的研究 RGSS3 (七) 加入LOGO屏幕
对于游戏 LOGO 屏幕. 首先设计 LOGO Scene类.我们知道,现场类 Scene_Base 子类. 让我们回顾一下现场的作品. 首先运行开始处理.其次是开始治疗.然后停止更新屏幕,最后,治疗 ...
- 【转载】深度解析Android中字体设置
原文:http://mobile.51cto.com/android-265238.htm 1.在Android XML文件中设置字体 可以采用Android:typeface,例如android:t ...
- MSDN官方XmlSerializer类导致内存泄漏和性能低
MSDN官方XmlSerializer类使用说明链接: http://msdn.microsoft.com/zh-CN/library/system.xml.serialization.xmlseri ...
- 一个小团队TDD游戏及实践
介绍的这个游戏是自己根据目前带的团队的实际情况来制定的, 在游戏实践过程中,收到了较好的效果,故打算把这个游戏分享出来,一是分享一下实践,而是集思广益,不断完善,更好的利用游戏来锻炼队伍.下面就将游戏 ...
- 使用with ties查询并列的数据
select top 1 with ties name,stuId,sex,score from stuInfo order by score desc
- 线程:Semaphore实现信号灯
Semaphore是一个计数的信号量,可以维护当前访问自身的线程个数,并提供了同步机制.使用Semaphore可以控制同时访问资源的线程个数,例如实现一个文件允许的线程访问数.打个通俗的比喻,Sema ...
- [Usaco2008 Dec]Patting Heads 轻拍牛头[筛法]
Description 今天是贝茜的生日,为了庆祝自己的生日,贝茜邀你来玩一个游戏. 贝茜让N(1≤N≤100000)头奶牛坐成一个圈.除了1号与N号奶牛外,i号奶牛与i-l号和i+l号奶 ...