首页 技术 正文
技术 2022年11月22日
0 收藏 408 点赞 2,429 浏览 1083 个字

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848