ZOJ3549 Little Keng(快速幂)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Little Keng
Time Limit: 2 Seconds Memory Limit: 65536 KB
Calculate how many 0s at the end of the value below:
1n + 2n + 3n + ... + mn
Input
There are multiple cases. For each cases, the input containing two integers m, n. (1 <= m <= 100 , 1 <= n <= 1000000)
Output
One line containing one integer indicatint the number of 0s.
Sample Input
4 3
Sample Output
2
看完这题,感觉0的位数不会很多,拿Java大数跑了一部分数据,发现就直接取1e9没什么问题,然后就直接搞了。
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author xyiyy @https://github.com/xyiyy
*/ #include <iostream>
#include <fstream> //#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype> using namespace std;
#define rep2(X, L, R) for(int X=L;X<=R;X++)
typedef long long ll; //
// Created by xyiyy on 2015/8/5.
// #ifndef ICPC_QUICK_POWER_HPP
#define ICPC_QUICK_POWER_HPP
typedef long long ll; ll quick_power(ll n, ll m, ll mod) {
ll ret = ;
while (m) {
if (m & ) ret = ret * n % mod;
n = n * n % mod;
m >>= ;
}
return ret;
} #endif //ICPC_QUICK_POWER_HPP class TaskA {
public:
void solve(std::istream &in, std::ostream &out) {
int m, n;
while (in >> m >> n) {
ll ans = ;
rep2(i, , m)ans += quick_power(i, n, 1e9);
int cnt = ;
while (ans) {
if (ans % != )break;
cnt++;
ans /= ;
}
out << cnt << endl;
}
}
}; int main() {
std::ios::sync_with_stdio(false);
std::cin.tie();
TaskA solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return ;
}
ZOJ3549 Little Keng(快速幂)的更多相关文章
- BNUOJ 34985 Elegant String 2014北京邀请赛E题 矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 题目大意:问n长度的串用0~k的数字去填,有多少个串保证任意子串中不包含0~k的 ...
- 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)
题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...
- 51nod 算法马拉松18 B 非010串 矩阵快速幂
非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...
- hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)
题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3. ...
- Codeforces632E Thief in a Shop(NTT + 快速幂)
题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...
- GDUFE-OJ 1203x的y次方的最后三位数 快速幂
嘿嘿今天学了快速幂也~~ Problem Description: 求x的y次方的最后三位数 . Input: 一个两位数x和一个两位数y. Output: 输出x的y次方的后三位数. Sample ...
- 51nod 1113 矩阵快速幂
题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...
- 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】
还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...
- HDU5950(矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...
随机推荐
- Bug :”解压压缩文件失败: cpio; 在头中不存在归档“
问题描述: 在rpm包目录下执行rpm -ivh *rpm -force时,出现标题错误 解决办法: *src.rpm包也就源码包不能被直接进行安装,需要先将src.rpm包进行编译生成二进制的rpm ...
- for-in语句
<script type="text/javascript"> /* for-in语句: for-in语句的格式: for(var 变量名 in 遍历的目标){ } f ...
- 关于c语言不定参数的研究
一. 学习过程 编写程序如下: 编译连接并用debug加载,观察main函数的内容: Showchar函数的内容: 观察发现,main函数要传递两个参数‘a’和2,在汇编代码中是先将2赋给ax,再将a ...
- linux系统ecshop拿shell方法
Title:linux系统ecshop拿shell方法 --2011-06-08 13:23 最近弄一个站,对ECSHOP拿shell不了解,导致走了很多的弯路. nginx/0.8.54的服务器, ...
- 专门讲讲这个MYSQL授权当中的with grant option的作用
对象的owner将权限赋予某个用户(如:testuser1) grant select ,update on bd_corp to testuser1 [with grant option ]1.如果 ...
- Altium Designer同一个工程里不同原理图导入到不同的PCB
问题: 在用Altium Designer进行PCB工程设计时,有时一个工程里可能不止一块PCB,比如,一个设备里有主板和扩展板或者按键板等等,这时就需要在一个工程里添加多个PCB文件.如图: 我们知 ...
- INNO setup 制作安装包
1.获取SQLserver安装路径vardbpath:string;rtn:boolean;rtn := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWA ...
- crontab,at命令,常见问题
crontab命令 前 一天学习了 at 命令是针对仅运行一次的任务,循环运行的例行性计划任务,linux系统则是由 cron (crond) 这个系统服务来控制的. Linux 系统上面原本就有非常 ...
- RSA算法python实现
RSA算法是一种非对称加密算法,是现在广泛使用的公钥加密算法,主要应用是加密信息和数字签名.详情请看维基:http://zh.wikipedia.org/wiki/RSA%E5%8A%A0%E5%AF ...
- libvirt-adabddad
kvm i686 libvirtError: internal error cannot load AppArmor profile 'libvirt-adabddad-35ba-b9ca-e250 ...