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. gunzip

    gunzip——解压缩.gz的压缩文件 GNU unzip 命令所在路径:/bin/gunzip 示例1: # gunzip services.gz 解压缩当前目录下的services.gz文件,执行 ...

  2. caffe修改需要的东西 6:40

    https://blog.csdn.net/zhaishengfu/article/details/51971768?locationNum=3&fps=1

  3. struts2基于注解的action

    使用注解来配置Action的最大好处就是可以实现零配置,但是事务都是有利有弊的,使用方便,维护起来就没那么方便了. 要使用注解方式,我们必须添加一个额外包:struts2-convention-plu ...

  4. ajax通信

    AJAX即Asynchronous JavaScript and XML(异步的 JavaScript 和 XML),可以在不重新加载整个网页的基础上,对网页的某部分进行更新. XMLHttpRequ ...

  5. [BZOJ] 2662: [BeiJing wc2012]冻结

    https://www.lydsy.com/JudgeOnline/problem.php?id=2662 第一次写分层图(捂脸) 一开始真的naive地建图了,T到飞起.. 可以省下建图的空间,直接 ...

  6. 哪些 Python 库让你相见恨晚?

    知乎用户,A European Swallow. 苇叶.Aran He.jerry等人赞同 补充三个有助于自动化日常工作的: sh:sh 1.08 — sh v1.08 documentation可以 ...

  7. Python旅途——入门基础

    1.入门 ​ 作为近几年计算机程序设计语言中很火的Python,是一种面向对象的动态类型语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大 ...

  8. 剑指Offer(书):链表的倒数第K个节点

    题目:输入一个链表,输出该链表中倒数第k个结点. 分析:要注意三点:链表为空:链表个数小于k:k的值<=0; public ListNode FindKthToTail(ListNode hea ...

  9. JavaScript正则表达式-定义

    通过RegExp()构造函数创建RegExp对象来定义正则表达式. var reg_pattern = new RegExt("a\d"); 通过字面语法直接定义正则表达式. va ...

  10. json分享

    JSON是什么? JavaScript Object Notation (JSON) is a text format for the serialization of structured data ...