Problem Description

Given a positive integer N, you should output the most right digit of N^N.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).

Output

For each test case, you should output the rightmost digit of N^N.

Sample Input

2
3
4

Sample Output

7 6

Hint

In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.

解题思路:简单的快速幂取模运算,水过!
AC代码:
 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL mod_power(LL a,LL b,int mod){
LL ans=;
while(b){
if(b&)ans=ans*a%mod;
a=a*a%;
b>>=;
}
return ans;
}
int main(){
int t;LL n;
while(cin>>t){
while(t--){
cin>>n;
cout<<mod_power(n,n,)<<endl;
}
}
return ;
}

题解报告:hdu 1061 Rightmost Digit(快速幂取模)的更多相关文章

  1. HDU 1061 Rightmost Digit --- 快速幂取模

    HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...

  2. HDU 1061.Rightmost Digit-规律题 or 快速幂取模

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

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

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

  4. 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)

    先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...

  5. POJ3641-Pseudoprime numbers(快速幂取模)

    题目大意 判断一个数是否是伪素数 题解 赤果果的快速幂取模.... 代码: #include<iostream> #include<cmath> using namespace ...

  6. 杭电 2817 A sequence of numbers【快速幂取模】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 解题思路:arithmetic or geometric sequences 是等差数列和等比数 ...

  7. 【转】C语言快速幂取模算法小结

    (转自:http://www.jb51.net/article/54947.htm) 本文实例汇总了C语言实现的快速幂取模算法,是比较常见的算法.分享给大家供大家参考之用.具体如下: 首先,所谓的快速 ...

  8. UVa 11582 (快速幂取模) Colossal Fibonacci Numbers!

    题意: 斐波那契数列f(0) = 0, f(1) = 1, f(n+2) = f(n+1) + f(n) (n ≥ 0) 输入a.b.n,求f(ab)%n 分析: 构造一个新数列F(i) = f(i) ...

  9. 九度OJ 1085 求root(N, k) -- 二分求幂及快速幂取模

    题目地址:http://ac.jobdu.com/problem.php?pid=1085 题目描述: N<k时,root(N,k) = N,否则,root(N,k) = root(N',k). ...

随机推荐

  1. http post提交数组

    方式一:@RequestParam方式 服务提供方用@RequestParam注解接收参数,参数类型为long数组: @ApiOperation(value = "***", ta ...

  2. [转]如何阅读android framework源码

    但如果想深入的了解Android系统, 那么可以看下我的一些简单的总结. 知识 Java Java是AOSP的主要语言之一. 没得说, 必需熟练掌握. 熟练的Android App开发 Linux A ...

  3. Jquery EasyUI动态生成Tab

    function addTab(title, url) { if ($('#tt').tabs('exists', title)) { $('#tt').tabs('select', title); ...

  4. linux以下安装dnw

    [root@embedded secbulk]# make -C /lib/modules/`uname -r`/build M=`pwd` modules make: *** /lib/module ...

  5. [Java Sprint] Spring Configuration Using Java

    There is no applicationContext.xml file. Too much XML Namespaces helped Enter Java Configuration Cre ...

  6. JSP自己定义标签入门实例具体解释

    JSP自己定义标签主要能用到的两个包 javax.servlet.jsp.*;javax.servlet.jsp.tagext.*; 自己定义标签<userInfo:showUserInfo/& ...

  7. C#如何使用右下角托盘图标notifyIcon

    1 拖放一个NotifyIcon控件,并设置图标,还有显示的文字   2 双击这个控件,即当最小化了主窗体,然后双击这个右下角图标的时候,要显示主窗体(大部分程序的用户体验都是这样干的,比如QQ,双击 ...

  8. 使用Charles进行网络抓包

    一.安装Charles 二.使用 1.http抓包 1.1 现在我们默认是在进行iOS开发,首先确保iPhone和Mac是在同一个局域网下(连同一个WiFi).然后查看Mac的IP地址(打开网络偏好设 ...

  9. selenium第三课(selenium八种定位页面元素方法)

    selenium webdriver进行元素定位时,通过seleniumAPI官方介绍,获取页面元素的方式一共有以下八种方式,现按照常用→不常用的顺序分别介绍一下. 官方api地址:https://s ...

  10. 2016/1/21 练习 arraylist 1,添加 add() 2,遍历集合

    package shuzu; public class Customer { //从源码中 使用字段生成构造函数 public Customer(String good, int price) { s ...