快速排幂-----Digit Rightmost
来源:互联网 发布:php在线讲解 编辑:程序博客网 时间:2024/05/01 00:08
Problem D: Digit Rightmost
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 78 Solved: 12
[Submit][Status][Web Board]
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
<span class="sampledata" style="font-family: monospace; font-size: 18px; white-space: pre; background-image: none; background-attachment: scroll; background-color: rgb(141, 184, 255); background-position: 0px 0px; background-repeat: repeat repeat;">234</span>
Sample Output
<span class="sampledata" style="font-family: monospace; font-size: 18px; white-space: pre; background-image: none; background-attachment: scroll; background-color: rgb(141, 184, 255); background-position: 0px 0px; background-repeat: repeat repeat;">76</span>
HINT#include <stdio.h>int f(int a,int b,int p) { int temp = 1; while(b) { if(b & 0x01) { temp = (temp * (a%p)) % p; } a = ( (a%p) * (a%p) ) % p; b >>= 1; } return temp; } int main() { int a,n,t; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d\n",f(n,n,10)); } return 0; }
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.
0 0
- 快速排幂-----Digit Rightmost
- HDU Rightmost Digit (快速幂)
- Rightmost Digit(快速幂)
- HDU 1061 Rightmost Digit 【快速求幂】
- HDU 1061-Rightmost Digit(快速幂)
- hdu 1061 Rightmost Digit 快速幂
- hdu 1061 Rightmost Digit(快速幂)
- HDU 1061 Rightmost Digit(快速幂)
- HDU 1061 Rightmost Digit(快速幂)
- hdu1061 Rightmost Digit 标准快速幂
- ACM--快速幂--HDOJ 1061--Rightmost Digit
- HDU 1061 Rightmost Digit (快速幂)
- HDOJ 1061 Rightmost Digit(快速幂)
- 【HDU】1061 - Rightmost Digit(快速幂)
- 快速幂算法(hdu) Rightmost Digit
- HDU1061 Rightmost Digit【快速模幂】
- Rightmost Digit 【hdu-1061】【快速幂】
- hdu1061 Rightmost Digit 【快速幂模板】
- linux中likely与unlikely
- MFC中隐藏、显示菜单栏
- light oj 1236 【大数分解】
- 18大经典数据挖掘算法小结
- Ubuntu server 14.04 配置Memcache,以及Memcache的简单使用
- 快速排幂-----Digit Rightmost
- struct和typedef struct区别详解
- csdn 黑白球
- The C10K problem翻译
- 等高布局
- python面试题大全
- 获取CPU序列号、网卡MAC地址、硬盘序列号
- 浅谈C++多态性
- [JSOI2007] 奶酪 题解 贪心 O(1)