poj 2720 Last Digits
|
Last Digits
Description Exponentiation of one integer by another often produces very large results. In this problem, we will compute a function based on repeated exponentiation, but output only the last n digits of the result. Doing this efficiently requires careful thought about how to avoid computing the full answer.
Given integers b, n, and i, we define the function f(x) recursively by f(x) = bf(x-1) if x > 0, and f(0)=1. Your job is to efficiently compute the last n decimal digits of f(i). Input The input consists of a number of test cases. Each test case starts with the integer b (1 <= b <= 100) called the base. On the next line is the integer i (1 <= i <= 100) called the iteration count. And finally, the last line contains the number n (1 <= n <= 7), which is the number of decimal digits to output. The input is terminated when b = 0.
Output For each test case, print on one line the last n digits of f(i) for the base b specified. If the result has fewer than n digits, pad the result with zeroes on the left so that there are exactly n digits.
Sample Input 2 Sample Output 0065536 Source |
/*
* @Author: Lyucheng
* @Date: 2017-08-07 15:47:29
* @Last Modified by: Lyucheng
* @Last Modified time: 2017-08-07 20:10:43
*/
/*
题意:定义一个函数f(i)=b^(f(i-1)),给你b,i,n让你求f(i)的后n位,不足的用前导零补充 思路:后n位就是f(n)%(10^n) 问题:超时...打表
LL b,n,i;
LL mod;
char str[10];
LL pos;
char format[] = "%00d\n"; inline LL power(LL a,LL b,LL mod){//a的b次方
if(b==0) return 1;
LL cnt=power(a,b/2,mod);
cnt=cnt*cnt%mod;
if(b%2==1) cnt=cnt*a%mod;
return cnt;
} // return f(x)%mod
inline LL fun(LL b,LL x,LL mod){
if(x==0) return 1LL;//如果是0次,那么就是1
else{
LL res=power(b,fun(b,x-1,mod),mod);
if(res==0) res=mod;
return res;
}
}
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; int a[][]={
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},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,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,},
{,,,,,,,,,,,,}, };
int b,i,n; int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(scanf("%d",&b)!=EOF&&b){
scanf("%d%d",&i,&n);
string s="";
int pos=a[b-][(i>?:i)];
for(int i=;i<n;i++){
s+=pos%+'';
pos/=;
}
while(n--){
cout<<s[n];
}cout<<endl;
}
return ;
}
poj 2720 Last Digits的更多相关文章
- poj 3373 Changing Digits (DFS + 记忆化剪枝+鸽巢原理思想)
http://poj.org/problem?id=3373 Changing Digits Time Limit: 3000MS Memory Limit: 65536K Total Submi ...
- POJ 3373 Changing Digits(DP)
题目链接 记录路径的DP,看的别人的思路.自己写的也不好,时间居然2000+,中间的取余可以打个表,优化一下. 写的各种错,导致wa很多次,写了一下午,自己构造数据,终于发现了最后一个bug. dp[ ...
- POJ 3373 Changing Digits 好蛋疼的DP
一開始写的高位往低位递推,发现这样有些时候保证不了第四条要求.于是又開始写高位往低位的记忆化搜索,又发现传參什么的蛋疼的要死.然后又发现高位開始的记忆化搜索就是从低位往高位的递推呀,遂过之. dp[i ...
- POJ 3373 Changing Digits 记忆化搜索
这道题我是看了别人的题解才做出来的.题意和题解分析见原文http://blog.csdn.net/lyy289065406/article/details/6698787 这里写一下自己对题目的理解. ...
- POJ 3373 Changing Digits
题目大意: 给出一个数n,求m,使得m的长度和n相等.能被k整除.有多个数符合条件输出与n在每位数字上改变次数最小的.改变次数同样的输出大小最小的. 共同拥有两种解法:DP解法,记忆化搜索的算法. ...
- POJ 3548 Restoring the digits
暴力搜索.注意题目说每个字母对应的数字不同,这句话表明最多只有10个字母,所以暴力DFS绝对不会TLE. #include<cstdio> #include<cstring> ...
- ACM : POJ 2676 SudoKu DFS - 数独
SudoKu Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu POJ 2676 Descr ...
- [ACM训练] 算法初级 之 搜索算法 之 广度优先算法BFS (POJ 3278+1426+3126+3087+3414)
BFS算法与树的层次遍历很像,具有明显的层次性,一般都是使用队列来实现的!!! 常用步骤: 1.设置访问标记int visited[N],要覆盖所有的可能访问数据个数,这里设置成int而不是bool, ...
- POJ 2151 Check the difficulty of problems
以前做过的题目了....补集+DP Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K ...
随机推荐
- 转换时间对象和字符串对象&添加时间
/* *基本思路,将字符串时间转化为时间对象,通过毫秒数来加减时间,然后在转化为字符串输出 */ //转化字符时间yy-mm-dd hh:mm:ss 为时间对象 使用split进行字符串的分割,取 ...
- 《Node.js在CLI下的工程化体系实践》成都OSC源创汇分享总结
背景: 随着开发团队规模不断发展壮大,在人员增加的同时也带来了协作成本的增加,业务项目越来越多,类型也各不相同.常见的类型有组件类.活动类.基于React+redux的业务项目.RN项目.Node.j ...
- 分享基于分布式Http长连接框架--代码模型
好的代码应该是方便客户端使用,代码能够自描述,规范化,大众标准化. 而且我相信代码也是有生命的,需要不断的维护它,你以什么样的态度对待它,它就会以同样的态度回敬你,所以在写代码前,先摆好自己的态度(一 ...
- hdu3729二分匹配
I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu2157矩阵快速幂
How many ways?? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 1042 数字0-9的数量 1050 循环数组最大子段和 1062 序列中最大的数 1067 Bash游戏 V2 1092 回文字符串
1042 数字0-9的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 给出一段区间a-b,统计这个区间内0-9出现的次数. 比如 10-19,1出现11次 ...
- MySQL之增删改查
前言:以下是MySQL最基本的增删改查语句,很多IT工作者都必须要会的命令,也是IT行业面试最常考的知识点,由于是入门级基础命令,所有所有操作都建立在单表上,未涉及多表操作. 前提:在进行" ...
- 学习总结---OSPF协议
总结: 1.ospf协议报文不会泛洪扩散,而是逐级路由器处理后,再从所有ospf启用端口发送出去,也就是说,只能从邻居接收到ospf报文,报文的源ip是邻居的ip地址,目的ip是组播ip. 2.开启o ...
- 关于python安装一些包时出现的错误解决方法
1.关于wordcloud的安装 --win10,py3.6环境下安装总是出现安装错误,解决方法,下载wordcloud的wheel文件,进行安装. 详情参考:https://github.com/a ...
- win10 UWP button
button有很多和wpf一样,可以看<深入浅出WPF> 我们可以在button的click写上 <Button Content="确定" Click=" ...