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 ...
随机推荐
- js 获取节点
var chils= s.childNodes; //得到s的全部子节点 var par=s.parentNode; //得到s的父节点 var ns=s.nextSbiling; //获得s的下一个 ...
- MongoDB insert/update/one2many案例
以博文与评论为例,博文有标题内容,对应多个评论,评论有评论人.评论内容等. ()插入一条博文: db.blog.insert( {','title':'this is blog title1','co ...
- BZOJ1119: [POI2009]SLO
1119: [POI2009]SLO Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 379 Solved: 181[Submit][Status] ...
- 设计模式 ( 十六 ): Mediator中介者模式 -- 行为型
1.概述 在面向对象的软件设计与开发过程中,根据“单一职责原则”,我们应该尽量将对象细化,使其只负责或呈现单一的职责,即将行为分布到各个对象中. 对于一个模块或者系统,可能由很多对象构成,而且这些对象 ...
- 【转】Win8/8.1/Win7小技巧:揪出C盘空间占用的真凶
原文网址:http://www.ithome.com/html/win8/55496.htm 不少使用Win8.Win8.1的用户不难发现,原先只占用20G大小的系统盘,随着使用时间的增加,C盘的磁盘 ...
- mysql优化整理(索引)
什么是索引? 索引是表记录的单个或多个字段重新组织的一种方法,其目的是提高数据库的查询速度,本质上就是一种数据结构. 索引的类型:primary(主键).secondary(其他) 索引的数据结构 I ...
- Spark standalone安装(最小化集群部署)
Spark standalone安装-最小化集群部署(Spark官方建议使用Standalone模式) 集群规划: 主机 IP ...
- JS浏览器对象-window对象
代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...
- yii 分页 (ajax)
Controller:class MemberController extends Controller { public function actionmember_list() { ...
- JavaScript 单例模式实现
Singleton模式指的是调用一个类,任何时候返回的都是同一个实例. 对于Node来说,模块文件可以看成是一个类.怎么保证每次执行这个模块文件,返回的都是同一个实例呢? 很容易想到,可以把实例放到顶 ...