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

思路:这题是真正的水题,直接套用模板QAQ

#include<bits/stdc++.h>
using namespace std;
long long PowerMod(long long a, long long b, long long c)
{
long long ans = 1;
a = a % c; //对刚进来的a进行取模运算,避免后面第一次求平方运算溢出
while(b)
{
if(b&1) //相当于b % 2 = = 1对二进制下的 b 进行按位与1运算,求二进制下 b 的最低位是否为1
ans = ans * a % c; //对结果进行保存
b>>=1; //相当于b = b/2;二进制下的 b 右移一位,相当于十进制下的 b 除以2
a = a * a % c;
}
return ans;
} int main()
{
long long t,n,m;
cin>>t;
while(t--)
{
cin>>n;
m=PowerMod(n,n,10);
cout<<m<<endl;
}
return 0;
}

HDU1061 - Rightmost Digit的更多相关文章

  1. Rightmost Digit

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

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

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

  3. hdoj 1061 Rightmost Digit【快速幂求模】

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

  4. HDOJ 1061 Rightmost Digit(循环问题)

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

  5. Rightmost Digit(快速幂+数学知识OR位运算) 分类: 数学 2015-07-03 14:56 4人阅读 评论(0) 收藏

    C - Rightmost Digit Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...

  6. Rightmost Digit(快速幂)

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

  7. <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字

    1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...

  8. 杭电 1061 Rightmost Digit计算N^N次方的最后一位

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

  9. HDOJ 1061 Rightmost Digit

    找出数学规律 原题: Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

随机推荐

  1. C语言基础 (10) 变量作用域,生命周期 内存结构

    01 课程回顾 1.指针数组 注意: 对于数组来说,在使用sizeof的时候a和&a[0]是不一样的, 虽然以%x打印出来他们都是地址 2.值传递 int a; fun(a); int *** ...

  2. 2018年九个很受欢迎的vue前端UI框架

    最近在逛各大网站,论坛,SegmentFault等编程问答社区,发现Vue.js异常火爆,重复性的提问和内容也很多,小编自己也趁着这个大前端的热潮,着手学习了一段时间的Vue.js,目前用它正在做自己 ...

  3. iis配置问题报错 -- Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies

    具体提示: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. 试图加载格式不正确的程序. ...

  4. 面试宝典之基本的C#面试问答

    下文是100个基本的C#面试问答清单.这些面试问题简单.直接了当,涵盖了C#最基本的概念,大部分和面向对象的概念相关.所以如果你在准备C#面试,我建议你必须掌握这100个基本的C#面试问答来复习你的C ...

  5. Arduino Yun高速新手教程(大学霸内部资料)

    Arduino Yun高速新手教程(大学霸内部资料) 本资料为国内第一本Arduino Yun教程.具体解说Arduino Yun的基本结构.开发环境.系统配置.并着力解说关键功能--Bridge.最 ...

  6. android setCookie 免登录

    CookieSyncManager.createInstance(getActivity()); CookieManager cookieManager = CookieManager.getInst ...

  7. UVA 1149 Bin Packing 二分+贪心

    A set of n 1-dimensional items have to be packed in identical bins. All bins have exactly the samele ...

  8. yarn架构——本质上是在做解耦 将资源分配和应用程序状态监控两个功能职责分离为RM和AM

    Hadoop YARN架构解读 原Mapreduce架构 原理架构图如下: 图 1.Hadoop 原 MapReduce 架构 原 MapReduce 程序的流程:首先用户程序 (JobClient) ...

  9. [jzoj 5664] [GDOI2018Day1模拟4.6] 凫趋雀跃 解题报告(容斥原理)

    interlinkage: https://jzoj.net/senior/#contest/show/2703/3 description: solution: 考虑容斥原理,枚举不合法的走的步数 ...

  10. 32.QT绘图

    widget.h #ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include <QPainter> #inclu ...