Problem G Power et al. Input: Standard Input

Output: Standard Output

Finding the exponent of any number can be very troublesome as it grows exponentially J. But in this problem you will have to do a very simple task. Given two non-negative numbers and n, you will have to find the last digit of mn in decimal number system.

Input

The input file contains less than 100000 lines. Each line contains two integers and n (Less than 10^101). Input is terminated by a line containing two zeroes. This line should not be processed.

Output

For each set of input you must produce one line of output which contains a single digit. This digit is the last digit of mn.

Sample Input 

2 2

2 5

0 0                            

Output for Sample Input

4

2

题目大意:求m^n的最后一位数字

打表出0、1、2、3、4、5、6、7、8、9(50次方以内的数)

发现规律,最长的周期为4

(0) 0 0 0 0

(1)1 1 1 1

(2)2 4 8 6

(3)3 9 7 1

(4)4 6 4 6

(5)5 5 5 5

(6)6 6 6 6

(7)7 9 3 1

(8)8 4 2 6

(9)1 9 1 9

AC代码:

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string a,b;
int f[][]=
{
,,,,
,,,,
,,,,
,,,,
,,,,
,,,,
,,,,
,,,,
,,,,
,,,
}; int deal()
{
int p=a[a.size()-]-'';
int i,ret=;
for(i=;i<b.size();i++)
ret=(ret*+b[i]-'')%;
return f[p][ret];
}
int main()
{
while(cin>>a>>b,!(a=="" && a==b))
{
if(b=="")
cout<<<<endl;
else
cout<<deal()<<endl;
}
return ;
}

uva 10515 规律打表的更多相关文章

  1. UVA 10515 - Powers Et Al.(数论)

    UVA 10515 - Powers Et Al. 题目链接 题意:求出m^n最后一位数 思路:因为m和n都非常大,直接算肯定是不行的,非常easy想到取最后一位来算,然后又非常easy想到最后一位不 ...

  2. 紫书 习题 10-13 UVa 11526(打表找规律+分步枚举)

    首先看这道题目,我预感商数肯定是有规律的排列的,于是我打表找一下规律 100 / 1 = 100 100 / 2 = 50  100 / 3 = 33  100 / 4 = 25  100 / 5 = ...

  3. UVA 10706 Number Sequence (找规律 + 打表 + 查找)

    Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A singl ...

  4. HDU 4731 找规律,打表

    http://acm.hust.edu.cn/vjudge/contest/126262#problem/D 分为3种情况,n=1,n=2,n>=3 其中需要注意的是n=2的情况,通过打表找规律 ...

  5. CF468A | 24 Game 找规律+打表

    (翻译版本来自 Luogu by lonelysir ) 题目描述 小X一直很喜欢一个纸牌游戏:"24点",但最近他发现这个游戏太简单了,所以他发明了一个新游戏. 你有一个整数序列 ...

  6. ACM-ICPC 2018 南京赛区网络预赛 - J. Sum (找规律+打表)

    题意:\(f(i):i\)能拆分成两个数的乘积,且要求这两个数中各自都没有出现超过1次的质因子.每次给出n,求\(\sum_{i=1}^{n}f(i)\) 分析:\(1 \le n \le 2e7\) ...

  7. UVA 1482 SG打表

    打出SG表来可以很容易的发现i为偶数时 SG[i]=i/2 i为奇数时 SG[i]=SG[i/2] #include<bits/stdc++.h> typedef long long ll ...

  8. UVA 10006(素数打表+快速幂)

    当今计算机科学的一个重要的领域就是密码学.有些人甚至认为密码学是计算机科学中唯一重要的领域,没有密码学生命都没有意义. 阿尔瓦罗就是这样的一个人,它正在设计一个为西班牙杂烩菜饭加密的步骤.他在加密算法 ...

  9. hdu 3032 Nim or not Nim? (sg函数打表找规律)

    题意:有N堆石子,每堆有s[i]个,Alice和Bob两人轮流取石子,可以从一堆中取任意多的石子,也可以把一堆石子分成两小堆 Alice先取,问谁能获胜 思路:首先观察这道题的数据范围  1 ≤ N ...

随机推荐

  1. SQL与脚本语言

    SQL是人类与数据库沟通的语言https://zhidao.baidu.com/question/413397944.html我个人认为SQL是一种专门对数据库进行操作的特殊的脚本语言.因为SQL语句 ...

  2. 关键字: on

    关键字: on 数据库在通过连接两张或多张表来返回记录时,都会生成一张中间的临时表,然后再将这张临时表返回给用户. 在使用left jion时,on和where条件的区别如下: 1. on条件是在生成 ...

  3. WPF中HyperLink超链接的使用

    HyperLink超链接的简单使用:  XAML里面: <TextBlock> <Hyperlink NavigateUri="http://www.baidu.com&q ...

  4. call和apply方法的异同

    基本作用:改变对象的执行上下文. this指向执行上下文.(执行环境) this指向的永远是调用该方法的对象 function func(){ this.a=1; console.log(this.a ...

  5. css--背景和列表

    背景 背景样式: background-color    设置元素的背景颜色 background-image  把图像设置为背景 background-repeat     设置背景图像是否重复及如 ...

  6. SpringBoot入门,新建SpringBoot项目

    一.在Spring Initializr中创建初始化项目 https://start.spring.io/ 二.通过maven导入Idea中(解压后的项目) 解压文件 黄色的为项目需要的真正的代码 , ...

  7. 毛毛虫组【Beta】Scrum Meeting 3

    第三天 日期:2019/6/25 前言 第三次会议: 时间:6月25日 地点:教10-A511 内容:此次会议主要是对项目验收做准备工作. 1.1 今日完成任务情况以及遇到的问题. 今日完成任务情况: ...

  8. url地址数据参数转化JSON对象(js三种方法实现)

    当我们用get方法提交表单时,在url上会显示出请求的参数组成的字符串,例如:http://localhost:3000/index.html?phone=12345678901&pwd=12 ...

  9. 【模拟】bzoj1686: [Usaco2005 Open]Waves 波纹

    打完模拟题来庆祝一波:):感觉最近陷入一种“口胡五分钟打题两小时”的巨坑之中…… Description Input     第1行:四个用空格隔开的整数Pj Bi,B2,R. P(1≤P≤5)表示石 ...

  10. kafka异常问题汇总

    1.报错:: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.NotLeaderForPartition ...