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. Hyperledger Fabric on SAP Cloud Platform

    今天的文章来自Wen Aviva, 坐Jerry面对面的程序媛. Jerry在之前的公众号文章<在SAP UI中使用纯JavaScript显示产品主数据的3D模型视图>已经介绍过Aviva ...

  2. SAP成都研究院郑晓霞:Shift Left Testing和软件质量保证的一些思考

    今天的文章来自Jerry的同事,曾经的搭档郑晓霞(Zheng Kate).郑晓霞是在Jerry心中是一位很有实力的程序媛,2011年从西安某软件公司跳槽到SAP成都研究院.当时,成都研究院的CRM团队 ...

  3. vue watch 监听

    1.普通的watch data() { return { frontPoints: 0 } }, watch: { frontPoints(newValue, oldValue) { console. ...

  4. iphone在jsp显示时间会NAN解决办法

    例:2018-12-28 15:00:00 1.   var  newDate = new Date("2018-12-28 15:00:00") 这种获取的时间在安卓手机上显示是 ...

  5. python hdfs初体验

    新建目录 chr 新建文件hdfstest1.txt并写入内容 复制hdfstest1.txt的内容到hdfstest2.txt

  6. Python基础篇 -- if while 语句

    2.7 if语句 # 单纯if if 条件: 代码块 当条件成立,执行代码块 # 二选一 if 条件: 代码块1 else: 代码块2 #当条件为真,执行代码块1,否则执行代码块2 # 多选一 没有e ...

  7. JAVA遍历map元素

    第一种: Map map = new HashMap(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Ma ...

  8. 同时使用多个UITableView

    1.xib\storyboard中给2个tableView设置constraints(等宽) 方法 : ①设置mainTableView的上\下\左\三部分的约束为0:subTableView上\下\ ...

  9. RN在设备上运行

    https://facebook.github.io/react-native/docs/running-on-device.html 在发布之前,最好是在真实的设备上测试一下应用.如果是通过crea ...

  10. 关于ajax在微信智能客服管理端的使用

    ajax的语法样例: $.ajax({ 'url':url, 'type':'GET', 'dataType':'json', 'data':data, success:function (data) ...