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 ...
随机推荐
- [js高手之路] html5 canvas系列教程 - arc绘制曲线图形(曲线,弧线,圆形)
绘制曲线,经常会用到路径的知识,如果你对路径有疑问,可以参考我的这篇文章[js高手之路] html5 canvas系列教程 - 开始路径beginPath与关闭路径closePath详解. arc:画 ...
- 初学node.js有感二
node.js进阶 一.回顾与继续 对于一种语言的认识都是经历这样的一个过程的,首先从原生的环境(CMD)中开始学习,找到一门语言之间各种引用的本质和相互之间的调用方式,明澈各种依赖关系,在这个基 ...
- JSP入门3 Servlet
需要继承类HttpServlet 服务器在获得请求的时候会先根据jsp页面生成一个java文件,然后使用jdk的编译器将此文件编译,最后运行得到的class文件处理用户的请求返回响应.如果再有请求访问 ...
- Javascript写的一个可拖拽排序的列表
自己常试写了一个可拖拽进行自定义排序的列表,可能写的不太好,欢迎提供意见. 我的思路是将列表中的所有项都放进一个包裹层,将该包裹层设为相对定位,每当点击一个项时,将该项脱离文档并克隆一份重新添加到文档 ...
- SQL监测语句
SELECT top 20 qs.creation_time,last_execution_time,total_physical_reads,total_logical_reads,total_lo ...
- HTML协议详解
一.实验环境搭建 因agileone很久没有更新,所以安装时需要注意版本.个人验证,如下版本可用: 1.XAMPP 实验版本:XAMPP for Windows Version 1.6.8 下载地址: ...
- 改变ListBoxItem选中的颜色
改变ListBoxItem主要是改变的style 下面直接看代码吧!!! <Style TargetType="{x:Type ListBoxItem}"> <S ...
- SpringMVC拦截器Interceptor
SpringMVC拦截器(Interceptor)实现对每一个请求处理前后进行相关的业务处理,类似与servlet中的Filter. SpringMVC 中的Interceptor 拦截请求是通过Ha ...
- oracle temporary table
oralce 有两种临时表 a.会话级临时表 b.事物级临时表 A.事物级临时表 语法 create global temporary table table_name( col1 type1, ...
- Swift搭建服务端
原文:Hello Server Side Swift 作者:Logan Wright 译者:CocoaChina--kmyhy(博客) 自从苹果官方发布了一个 Swift 的 Linux 开源版本之后 ...