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 ...
随机推荐
- SQL Server 远程链接服务器详细配置
原文:SQL Server 远程链接服务器详细配置[转载] http://hi.baidu.com/luxi0194/blog/item/a5c2a9128a705cc6c2fd7803.html - ...
- android 首开机会在数据链接图标的状态栏打开并自行消失主动
请找到该文件ConnectivityService.java (alps\frameworks\base\services\java\com\android\server) 在connectivit ...
- postal邮件发送(二):Email headers,附件,图片介绍
接上篇 http://www.cnblogs.com/mybky/p/5690567.html 1.邮件headers 除此之外,还有Reply-To,用于回复邮箱 2.邮件带有图片 邮件发送图片,p ...
- 【转】【Android工具】被忽略的UI检视利器:Hierarchy Viewer
原文:http://blog.csdn.net/ddna/article/details/5527072 Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下, ...
- idea中output log4j中文乱码
1.设置tomcat中的VM optins:-Dfile.encofing=UTF-8 2.idea安装目录bin文件夹中idea.exe.vmoptions.idea64.exe.vmoptions ...
- JAVA 作业:图形界面
自己动手写的一个小JAVA 程序: 一个学生管理小系统,虽然很挫,但是这我学JAVA的第一步.学了2天JAVA没有白费! import java.awt.*; import java.awt.even ...
- Moq 测试 属性,常用方法
RhinoMock入门(7)——Do,With和Record-playback 摘要: (一)Do(delegate)有时候在测试过程中只返回一个静态的值是不够的,在这种情况下,Do()方法可以用来在 ...
- DOM事件简介
DOM事件简介--摘自ADMIN10000 Posted on 2013-12-05 09:32 ziran 阅读(76) 评论(1) 编辑 收藏 Click.touch.load.drag.chan ...
- noip模拟赛:电话时间[字符串]
[问题描述] 某人总是花很多时间给父母打电话.有一次他记录了打电话的开始时间和结束时刻t1和t2,请你帮他算算此次通话一共用了多少秒.又有一次,他记录了打电话的开始时刻t1和通话的时间长度len,请你 ...
- windows 常用操作
资源管理器 资源管理器中进入上一级目录:Alt+向上箭头 常用命令行命令 打开windows服务:services.msc 以管理员身份运行程序 按下Win键,在打开的窗口中输入命 ...