一些项目——Rightmost Digit
2015-05-30 17:13
537 查看
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.
代码
#include <iostream> using namespace std; int main() { long n,m,num,p; cin>>num; while(num--){ cin>>n; m = p = n % 10; if (n % 4 == 0) n = 4; else n = n % 4; while(--n) p = (p * m) % 10; cout<<p<<endl; } return 0; }
主要还是找规律
相关文章推荐
- Java 线程同步
- Linux修改/etc/sysconfig/i18n后桌面无法显示
- 微信公众号辅助工具汇总 推广加粉统统有
- jquery-qrcode在线生成二维码
- LeetCode ---Remove Element
- log4j详解与实战
- Android 关于新浪微博的OAuth2.0授权
- 彩色图像,二值图像,灰度图像,不要傻傻分不清~
- 【团队分享】iOS8.3给发图带来的坑,怎样迅速填平?
- 网络开发总结
- 梦殇 chapter three
- 论企业租赁经营
- Python的Django框架中settings文件的部署建议
- 计算摄影学论文集锦
- 图书管理系统------软件设计图纸
- LeetCode ---Remove Duplicates from Sorted Array
- 个人空间
- MySQL5.5半同步复制配置安装
- 一些项目——Delta-wave
- 论市场机制和企业活力同步启动