Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
 
Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
 
Output
For each test case, you should output the a^b's last digit number.
 
Sample Input
7 66
8 800
 
Sample Output
9
6
 

这道题也是一道求最后一个数字的,只是方式稍微改变了一下...

 #include <iostream>
using namespace std;
int main()
{
int a,b;
int round=;
int r[]={};
int i=;
while(cin>>a>>b)
{
r[]=a%;
r[]=(a%)*(a%)%;//这里是关键,开始是a*a%10,提交提示WA。
for(i=;;i++)
{
r[i]=r[i-]*(a%)%;
if(r[i]==r[])
{round=i-;break;}
}
if(b%round==)
cout<<r[round]<<endl;
else cout<<r[b%round]<<endl;
}
return ;
}

HDOJ 1097 A hard puzzle的更多相关文章

  1. HDOJ 1097 A hard puzzle(循环问题)

    Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how ...

  2. 【HDOJ】1097 A hard puzzle

    题目和1061非常相似,几乎可以复用. #include <stdio.h> ][]; int main() { int a, b; int i, j; ; i<; ++i) { b ...

  3. hdu 1097 A hard puzzle 快速幂取模

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1097 分析:简单题,快速幂取模, 由于只要求输出最后一位,所以开始就可以直接mod10. /*A ha ...

  4. hdu 1097 A hard puzzle

    Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how ...

  5. 【HDOJ】1857 Word Puzzle

    trie树.以puzzle做trie树内存不够,从puzzle中直接找串应该会TLE.其实可以将查询组成trie树,离线做.扫描puzzle时注意仅三个方向即可. /* 1857 */ #includ ...

  6. HDOJ 1098 Ignatius's puzzle

    Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he has no choice bu ...

  7. HDOJ 5411 CRB and Puzzle 矩阵高速幂

    直接构造矩阵,最上面一行加一排1.高速幂计算矩阵的m次方,统计第一行的和 CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  8. HDOJ 1755 - A Number Puzzle 排列数字凑同余,状态压缩DP

    dp [ x ] [ y ] [ z ] 表示二进制y所表示的组合对应的之和mod x余数为z的最小数... 如可用的数字为 1 2 3 4...那么 dp [ 7 ] [ 15 ] [ 2 ] = ...

  9. one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏

    one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...

随机推荐

  1. 【ORM】关于Dapper的一些常见用法

    引言 Dapper是.Net平台下一款小巧玲珑的开源Orm框架,简单实用的同时保持高性能,非常适合我这种喜欢手写SQL的人使用,下面介绍一下如何使用Dapper. 相关资料 Dapper的GitHub ...

  2. LeetCode OJ:Path Sum(路径之和)

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  3. Hadoop单机模式和伪分布式搭建教程CentOS

    1. 安装JAVA环境 2. Hadoop下载地址: http://archive.apache.org/dist/hadoop/core/ tar -zxvf hadoop-2.6.0.tar.gz ...

  4. codeigniter教程:Codeigniter出现Unable to connect to your databas

    Codeigniter出现A Database Error Occurred错误 下午把项目构建到服务器上的时候,codeigniter竟然出现了 a database error occurred ...

  5. 普通方法实现——远程方法调用RMI代码演示

    1.spring_RMI01_server服务端 package com.wisezone.service; import java.rmi.Remote; import java.rmi.Remot ...

  6. LeetCode Shopping Offers

    原题链接在这里:https://leetcode.com/problems/shopping-offers/description/ 题目: In LeetCode Store, there are ...

  7. 基于JQ的三级联动菜单选择

    <!-- author:青芒 --> <!DOCTYPE html> <html lang="en"> <head> <met ...

  8. git之clone

    git clone 命令参数: usage: git clone [options] [--] <repo> [<dir>] -v, --verbose be more ver ...

  9. Python获取%appdata%路径的方法

    import osimport sys import winreg print(os.name)print(sys.getdefaultencoding())print(sys.version)pri ...

  10. C++动多态和静多态

    动多态的设计思想:对于相关的对象类型,确定它们之间的一个共同功能集,然后在基类中,把这些共同的功能声明为多个公共的虚函数接口.各个子类重写这些虚函数,以完成具体的功能.客户端的代码(操作函数)通过指向 ...