uva 10515 规律打表
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 m 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 m 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 规律打表的更多相关文章
- UVA 10515 - Powers Et Al.(数论)
UVA 10515 - Powers Et Al. 题目链接 题意:求出m^n最后一位数 思路:因为m和n都非常大,直接算肯定是不行的,非常easy想到取最后一位来算,然后又非常easy想到最后一位不 ...
- 紫书 习题 10-13 UVa 11526(打表找规律+分步枚举)
首先看这道题目,我预感商数肯定是有规律的排列的,于是我打表找一下规律 100 / 1 = 100 100 / 2 = 50 100 / 3 = 33 100 / 4 = 25 100 / 5 = ...
- UVA 10706 Number Sequence (找规律 + 打表 + 查找)
Problem B Number Sequence Input: standard input Output: standard output Time Limit: 1 second A singl ...
- HDU 4731 找规律,打表
http://acm.hust.edu.cn/vjudge/contest/126262#problem/D 分为3种情况,n=1,n=2,n>=3 其中需要注意的是n=2的情况,通过打表找规律 ...
- CF468A | 24 Game 找规律+打表
(翻译版本来自 Luogu by lonelysir ) 题目描述 小X一直很喜欢一个纸牌游戏:"24点",但最近他发现这个游戏太简单了,所以他发明了一个新游戏. 你有一个整数序列 ...
- ACM-ICPC 2018 南京赛区网络预赛 - J. Sum (找规律+打表)
题意:\(f(i):i\)能拆分成两个数的乘积,且要求这两个数中各自都没有出现超过1次的质因子.每次给出n,求\(\sum_{i=1}^{n}f(i)\) 分析:\(1 \le n \le 2e7\) ...
- UVA 1482 SG打表
打出SG表来可以很容易的发现i为偶数时 SG[i]=i/2 i为奇数时 SG[i]=SG[i/2] #include<bits/stdc++.h> typedef long long ll ...
- UVA 10006(素数打表+快速幂)
当今计算机科学的一个重要的领域就是密码学.有些人甚至认为密码学是计算机科学中唯一重要的领域,没有密码学生命都没有意义. 阿尔瓦罗就是这样的一个人,它正在设计一个为西班牙杂烩菜饭加密的步骤.他在加密算法 ...
- hdu 3032 Nim or not Nim? (sg函数打表找规律)
题意:有N堆石子,每堆有s[i]个,Alice和Bob两人轮流取石子,可以从一堆中取任意多的石子,也可以把一堆石子分成两小堆 Alice先取,问谁能获胜 思路:首先观察这道题的数据范围 1 ≤ N ...
随机推荐
- 2018 北京区域赛 I - Palindromes (找规律)
题目 HihoCoder - 1878 题目大意 给出k,让求出第k个回文数(k的“长度”不超过1e5) 题解 之前做过类似的题,是统计各阶段的数找到第K个回文数,但这里K太大,需要寻找新的方法. 打 ...
- Codeforces Round #272 (Div. 2)-B. Dreamoon and WiFi
http://codeforces.com/contest/476/problem/B B. Dreamoon and WiFi time limit per test 1 second memory ...
- ios之UIWebView(1)
UIWebView可以让你创建一个网页浏览器,类似safari,而不是在程序中启动safsri哦.是不是觉得很棒呢?废话少说,切入正题. 一.创建UIWebView [java] view plain ...
- 一篇关于BEM命名规范
一直以来自己对命名都是比较混乱的,并没有一个比较好的格式来命名,最近自己碰巧学习到了BEM命名规范,我想谈谈自己的理解以供自己来学习,同时也可以和各位大佬一起学习. BEM是一个很有用的方法可以创建复 ...
- 解决 mounting /dev/block/mmcblk0p1 on /sdcard failed
http://www.liyu8.com/article/sdcard.htm 之前在recovery下的adb shell执行mount -a总是会有 mount: mouting /dev/blo ...
- windows终端输入pip install requests报错:Fatal error in launcher
emm今天群友发了个图,说他的pip报错,是这个问题 emmm这个问题我也不太懂,后来让他pip install requests这样操作,, 还是不管用,我寻思这个错咋回事,让他用 python ...
- Day05基本运算符,if判断和while循环
day05 1.常量 变量名全大写 2.基本运算符 ①算术运算 10/3除法 10//3取整 10*3乘法 10**3幂 ②赋值运算 增量赋值 age += 1#age = age + 1 age * ...
- Python9-递归函数-day17
# 计算方法:人脑复杂,计算机简单#查找:找数据#排序#最短路径#我们学习的算法都是过去时#要了解基础的算法,才能创造出更好的算法#不是所有的事情都能套用现成的方法解决的# 有些时候会用到学过的算法只 ...
- JavaScript正则表达式-字符类
字符列表 在方括号内指定一个或者多个字符组成的字符列表,与字符列表中任意字符匹配,都被认为是匹配的.每次匹配只能匹配列表中的一个字符. str = "bird,head,fed,meadow ...
- OpennSSL之基本了解
HTTPS是一种协议,等于HTTP+TLS(由于历史原因,SSL3.0之后就被TLS1.0替代了).openssl是一套开源工具集,主要有两个特性: 实现了ssl2,ssl3,TLSv1,TLSv1. ...