快速幂1003
来源:互联网 发布:数据库编程语言 编辑:程序博客网 时间:2024/05/17 07:25
Rightmost Digit
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 44 Accepted Submission(s) : 26
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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).
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
234
Sample Output
76
思路:这题可以用快速幂来做,只要每次都整除10,就不会变成大数了。
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <vector>using namespace std;int poww(long long int a,long long int b){ int m,n; m=1%10; n=a%10; while(b) { if(b&1) { m=(m*n)%10; } n=(n*n)%10; b>>=1; } return m;}int main(){ long long int T,n; cin>>T; while(T--) { cin>>n; cout<<poww(n,n)<<endl; } return 0;}
阅读全文
0 0
- 快速幂1003
- 快速矩阵快速幂
- 快速幂,快速幂取模
- 快速幂 + 快速幂取模
- 快速幂 快速幂取模
- 快速幂&&快速乘法
- 快速幂&快速乘
- 快速幂 快速乘法
- 快速幂 快速幂取模
- 快速幂+快速乘法
- 【快速幂】【快速幂取模】
- 快速乘法-快速幂
- 快速乘/快速幂/矩阵快速幂
- 快速乘 快速幂 矩阵快速幂
- 快速幂,快速幂取模,矩阵快速幂
- 快速幂
- 快速幂
- 快速幂
- PAT a1053题解
- 端口映射怎么设置
- Matlab如何真正自如的控制legend
- bzoj 3886: [Usaco2015 Jan]Moovie Mooving 状压dp
- PAT a1054题解
- 快速幂1003
- 电子书《程序原本》小述
- php 关联数组中随机的取出一个元素
- 关于网易公开课上南开数学文化的总结
- PAT a1055题解
- Service(远程服务)
- PAT a1056题解
- Matlab注释的几个方法
- excel入门,如何玩转excel,你早该这么玩Excel笔记11