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 ...
随机推荐
- 用es6的class关键字定义一个类
es6新增class关键字使用方法详解. 通过class关键字,可以定义类.基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对象原型的写法 ...
- Glide 这样用,更省内存!!!
一.前言 Glide 是 Google 官方推荐的一款图片加载库,使用起来也非常的简单便利,Glide 它帮我们完成了很多很重要,但是却通用的功能,例如:图片的加载压缩.展示.加载图片的内存管理等等. ...
- Centos7环境下使用Nginx托管.Net Core应用程序
一.安装.Net Core 参考官方文档:https://www.microsoft.com/net/core#linuxcentos 1.添加dotnet产品Feed 在安装.NET Core之前, ...
- Vuforia开发完全指南(四)--- Image Target
Vuforia开发完全指南---Image Target,简单方便的AR图像识别 概述 在Vuforia提供的SDK中,最简单.也是最常见的AR功能就是Image Target---图像识别.你只需提 ...
- 一脸懵逼学习基于CentOs的Hadoop集群安装与配置
1:Hadoop分布式计算平台是由Apache软件基金会开发的一个开源分布式计算平台.以Hadoop分布式文件系统(HDFS)和MapReduce(Google MapReduce的开源实现)为核心的 ...
- For in 与For of 区别
For in 与For of 区别 for in遍历的是数组的索引(即键名)一般用于遍历对象:for(var index in obj):而for of遍历的是数组元素值:for(var value ...
- SqlServer和Oracle中一些常用的sql语句5 流程控制语句
--在sql语句中 begin...end 用来设定一个程序块 相关于c#中的{} declare @yz real,@w int --声明变量 set @w=120 --为变量赋值 if @w< ...
- Windows下编译Python2.7源码
本文开始一个系列文章,深入理解Python源码,算是阅读<Python源码剖析>一书的读书笔记,是一项长期进行的工作.一共分三个部分:Python对象模型,Python虚拟机,Python ...
- WPF DataGrid自定义样式
微软的WPF DataGrid中有很多的属性和样式,你可以调整,以寻找合适的(如果你是一名设计师).下面,找到我的小抄造型的网格.它不是100%全面,但它可以让你走得很远,有一些非常有用的技巧和陷阱. ...
- Opencv如何捕获摄像头视频-OpenCV步步精深
捕获摄像头实时图像 这一点非常非常重要,因为这一点关乎了以后我们进行各种各样的识别(人脸识别,车牌识别等等有趣的识别).opencv提供了一个接口,可以轻松的让我们实现这个功能.我们先来看一段代码,根 ...