Codeforces 300C
题目链接: http://codeforces.com/contest/300/problem/C
本来是道不难的题目,还是自己的数学功底不扎实。
从该题又一次巩固了关于乘法逆的概念,在剩余系中,如果要做除法,如 a / b%n , 此时应该计算 a * (b在n下的逆), 而不是直接计算 a / b
另外一点值得注意的是,如果 n 为一素数,那么 b 的逆就是 pow_mod(a, n-2, n). 模拟叫做费马小定理。
乘法逆真的很重要。务必牢记!!!
附AC代码:
/*************************************************************************
> File Name: 300C.c
> Author: Stomach_ache
> Mail: 1179998621@qq.com
> Created Time: 2014年01月07日 星期二 17时32分26秒
************************************************************************/ #include<stdio.h>
#include<string.h>
#include<stdlib.h> #define mod 1000000007
typedef long long LL;
int a, b, n, c[], rfact[]; // c[] -> c(n, k).............rfack[] -> k在n下的逆 // x is good ?
int ok(int x) {
while (x > ) {
int tmp = x % ;
if (tmp != a && tmp != b)
return ;
x /= ;
} return ;
}
// quick mod
LL pow_mod(LL a, LL b, LL c) {
LL res = ;
while (b) {
if (b & )
res = (res * a) % c;
a = (a * a) % c;
b >>= ;
} return res % c;
} int main(void) {
while (~scanf("%d %d %d", &a, &b, &n)) {
int i, cur = a * n, d = b - a;
LL cnt = ok(cur);
c[] = ;
for (i = ; i <= n; i++) {
rfact[i] = pow_mod(i, mod-, mod);
c[i] = (LL)c[i - ] * (n - i + ) % mod;
c[i] = (LL)c[i] * rfact[i] % mod;
}
for (cur += d, i = ; i < n; i++, cur += d) {
if (ok(cur)) {
cnt += c[i];
cnt %= mod;
}
}
cnt = (cnt + ok(b * n)) % mod;
printf("%lld\n", cnt);
} return ;
}
Codeforces 300C的更多相关文章
- CodeForces 300C 最短路
A Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Pr ...
- CodeForces 300C --数论
A - A Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- CodeForces 300C Beautiful Numbers
枚举,组合数,逆元. 枚举$a$用了$i$个,那么$b$就用了$n-i$个,这个时候和$sum=a*i+b*(n-i)$,判断$sum$是否满足条件,如果满足,那么答案加上$C(n,i)$. #inc ...
- Codeforces 300C Beautiful Numbers 【组合数】+【逆元】
<题目链接> 题目大意: 给出a和b,如果一个数每一位都是a或b,那么我们称这个数为good,在good的基础上,如果这个数的每一位之和也是good,那么这个数是excellent.求长度 ...
- 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
[链接] 我是链接,点我呀:) [题意] 让你找到长度为n的数字 这个数字只由a或者b组成 且这n个数码的和也是由a或者b组成的 求出满足这样要求的数字的个数 [题解] 枚举答案数字中b的个数为y,那 ...
- [CodeForces 300C Beautiful Numbers]组合计数
题意:十进制的每一位仅由a和b组成的数是“X数”,求长度为n,各数位上的数的和是X数的X数的个数 思路:由于总的位数为n,每一位只能是a或b,令a有p个,则b有(n-p)个,如果 a*p+b*(n-p ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- diskpart
比如格式化成fat32 format fs=fat32 quick 比鼠标方便 如何使用: 打开cmd输入diskpart进入命令 首先 list disk 然后 然后 clean 然后 create ...
- java基础之Date类
Date类: Date类概述 类 Date 表示特定的瞬间,精确到毫秒. 构造方法 public Date() public Date(long date) 成员方法 public long getT ...
- linux与window文件传输(使用ssh+putty)
linux与window文件传输(使用ssh+putty) https://blog.csdn.net/Imagine_Dragon/article/details/78303241
- vue 全局方法(单个和多个方法)
参考: https://www.cnblogs.com/zhcBlog/p/9892883.html https://blog.csdn.net/xuerwang/article/d ...
- BZOJ4383/LuoGuP3588 Pustynia/PUS 线段树建图优化
我会告诉你我看了很久很久才把题目看懂吗???怀疑智商了 原来他给的l,r还有k个数字都是下标... 比如给了一个样例 l, r, k, x1,x2,x3...xk,代表的是一个数组num[l]~num ...
- 周期串Uva455 P37 3-4
A character string is said to have period k if it can be formed by concatenating one or more repetit ...
- Nginx报错汇总
1. Nginx 无法启动解决方法 在查看到 logs 中报了如下错误时: 0.0.0.0:80 failed (10013: An attempt was made to access a ...
- walle(瓦力)部署系统的安装和简单使用
Walle(瓦力):一套软件开发的部署系统.提供了清晰的日志记录,支持数据的回滚.用于解决大型团队在软件开发中的测试.预测试和上线的统一部署管理. 系统环境:CentOS6.8-A CentOS-6. ...
- centos Python2.6 升级到2.7
需求: centos 6.x 系统默认Python 版本都是2.6,实际生产环境中需要用到Python 2.7.x Python 2.7 下载地址 [root@ansible package]# wg ...
- 矩阵快速幂3 k*n铺方格
#include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...