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. LOJ#539. 「LibreOJ NOIP Round #1」旅游路线

    n<=100,m<=1000的图,在此图上用油箱容量C<=1e5的车来旅行,旅行时,走一条边会耗一单伟油,在点i时,若油量<ci,则可以把油以pi的价格补到ci,pi<= ...

  2. How to remote debug neutron

    First of all, I will assume that you know how to use pydevd to remote debug normal python program. I ...

  3. Project Perfect让Swift在server端跑起来-Perfect in Visual Studio Code (四)

    编者语 : 本系列文章已经被Perfect官方引用了,这样的感觉非常好.感恩!Thx all ! Visual Studio Code是一个轻量级的编辑器,但也功能丰富,通过插件你能够完毕如Cordo ...

  4. 蓝桥杯 地宫寻宝 带缓存的DFS

      历届试题 地宫取宝   时间限制:1.0s   内存限制:256.0MB      问题描写叙述 X 国王有一个地宫宝库. 是 n x m 个格子的矩阵. 每一个格子放一件宝贝. 每一个宝贝贴着价 ...

  5. MySQL-导入与导出

    CSV文件导入MySQL LOAD DATA INFILE语句允许您从文本文件读取数据,并将文件的数据快速导入数据库的表中. 导入文件操作之前,需要准备以下内容: 一.将要导入文件的数据对应的数据库表 ...

  6. web 开发之js---js 实现网页中播放wav的一种方法(flash播放器)

    http://blog.csdn.net/whumr1/article/details/6948160

  7. 2015/12/30 字符集 ASCII 到Unicode

    ——每个软件开发人员应该无条件掌握的知识! ——Unicode伟大的创想! 相信大家一定碰到过,打开某个网页,却显示一堆像乱码,如"бЇЯАзЪСЯ"."�??????? ...

  8. DNNClassifier 深度神经网络 分类器

    An Example of a DNNClassifier for the Iris dataset. models/premade_estimator.py at master · tensorfl ...

  9. 关于The hierarchy of the type TestBeforeAdvice is inconsistent的问题

    今天准备写一个spring aop的demo,创建了TestBeforeAdvice类,该类实现了MethodBeforeAdvice接口,eclipse报了"The hierarchy o ...

  10. 【Dairy】2016.10.23 观火&中彩记

    ...................... 就第一条可以! 观火10分钟,长郡附近老房子起火...