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 ...
随机推荐
- UCOS 请求任务删除函数 及其应用
有时候,如果任务A拥有内存缓冲区或信号量之类的资源,而任务B想删除该任务,这些资源就可能由于没被释放而丢失.在这种情况下,用户可以想法子让拥有这些资源的任务在使用完资源后,先释放资源,再删除自己.用户 ...
- ARC - strong和weak指针
ARC指南1 - strong和weak指针 提示:本文中所说的"实例变量"即是"成员变量","局部变量"即是"本地变量&qu ...
- 自定义cell 自适应高度
#pragma mark - 动态计算cell高度 //计算 返回 文本高度 + (CGFloat)calsLabelHeightWithContact:(Contacts *)contact { / ...
- grunt serve Warning: Running "sass:server" (sass) task
使用grunt serve运行时遇到一问题: y@y:ydkt$ grunt serve Running "serve" task Running "clean:serv ...
- mongodb工具
可视化管理工具 http://www.mongovue.com/ mongodb use case http://www.mongodb.org/about/applications/ mongodb ...
- Entity Framework with MySQL 学习笔记一(查看EF和SQL请求日志)
做数据库的一向来都会很注意请求的次数还有语句.这关系到很多性能的问题. 因此在使用EF的时候如果不了解原理很可能会搞出很糟糕的请求. 所以呢,在还没有搞懂EF前最基本的是你得"看得见&quo ...
- altium designer不经过原理图直接在空白pcb上加封装然后画线
如果是复杂点的PCB,建议还是画下SCH,如果PCB只有几个元件,那么可以用这种方法,想不画原理图,直接进行布线,往往是很多初学者最想知道的,但是这也一定不是初学者能学到的.因为你买的书,都是按画PC ...
- jmap命令结合mat插件分析内存泄露--OQL
http://smallnetvisitor.iteye.com/blog/1826434 User.java package gc; import java.util.ArrayList; impo ...
- YII 事件event和行为Behavior
To declare an event in your CComponent child class, you should add a method with aname starting with ...
- SQL-Employees Earning More Than Their Managers
思路: 今天复习数据库突然想起来leetcode上数据库的题目,就找来做了 (1)给表取别名 格式见code,这在自身连接的时候是很有必要的 (2)自身连接 from语句后面相当于接了“一张表”,如果 ...