51Nod-1004 n^n的末位数字【快速模幂】
来源:互联网 发布:吉林市知鼎人才网 编辑:程序博客网 时间:2024/05/21 08:35
1004 n^n的末位数字
题目来源: Author Ignatius.L (Hdu 1061)
基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题
给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字。
Input
一个数N(1 <= N <= 10^9)
Output
输出N^N的末位数字
Input示例
13
Output示例
3
问题链接:51Nod-1004 n^n的末位数字
问题分析:一个简单的快速模幂计算。
程序说明:快速模幂计算被封装到一个函数中,直接调用即可。题记:(略)
参考链接:(略)
AC的C++程序如下:
#include <iostream>using namespace std;// 快速模幂计算函数int powermod(long long a, int n, int m){ long long res = 1; while(n) { if(n & 1) { // n % 2 == 1 res *= a; res %= m; } a *= a; a %= m; n >>= 1; } return res;}int main(){ int n; cin >> n; cout << powermod(n, n, 10) << endl; return 0;}
阅读全文
0 0
- 51Nod-1004 n^n的末位数字【快速模幂】
- 51nod 1004 n^n的末位数字(快速幂)
- 51Nod 1004 n^n的末位数字(快速幂)
- 51nod 1004 n^n的末位数字
- 51nod-【1004 n^n的末位数字】
- 51nod 1004 n^n的末位数字
- 51nod 1004 n^n的末位数字
- 51NOD 1004 n^n的末位数字
- [51NOD] 1004 n^n的末位数字 [数学]
- 51nod 1004 n^n的末位数字
- 51Nod 1004 n^n的末位数字
- 【51Nod】1004 n^n的末位数字
- 51Nod--1004 n^n的末位数字
- 51nod 1004 n^n的末位数字
- 51nod 1004 n^n的末位数字
- 51Nod 1004 n^n的末位数字()
- 51nod 1004:n^n的末位数字
- 51NOD 1004 n^n的末位数字
- PHP的优缺点
- JavaScript基础知识(1)
- os 攻击 之 HTTP Flood 别名 cc攻击
- 11
- 在zkcli中怎样操作才会触发com.101tec.ZKClient实现中的subscribeDataChanges设置的监听器
- 51Nod-1004 n^n的末位数字【快速模幂】
- 电商 秒杀系统 设计思路和实现方法
- AIDL使用Demo
- 学生管理系统的设计与实现
- Linux账户的添加与删除
- 玩转linux之常见命令
- 玩转php之页面静态化
- ZooKeeper-3.3.4集群安装配置
- Python3 网络传输数据的处理(json / xml / base64)