HDU 1097 A hard puzzle(快速幂)
来源:互联网 发布:蚁群算法原理 编辑:程序博客网 时间:2024/05/31 13:14
此文章可以使用目录功能哟↑(点击上方[+])
HDU 1097 A hard puzzle
Accept: 0 Submit: 0
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
Output
For each test case, you should output the a^b's last digit number.
Sample Input
8 800
Sample Output
6
Problem Idea
解题思路:
【题意】
给你一个a和b,问a^b的最后一位数是多少
【类型】
快速幂
【分析】
乘法快速幂在幂运算方面还是比较常见的
通常,在幂运算中,幂较大时就会采用快速幂来缩短执行时间
而不是十分暴力的一项项乘
快速幂过程:
①对于奇数次幂
②对于偶数次幂
套个快速幂模板,此问题解决
【时间复杂度&&优化】
O(logn)
题目链接→HDU 1097 A hard puzzle
Source Code
/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<cmath>#include<complex>#include<string>#include<algorithm>#include<iostream>#define eps 1e-8#define LL long long#define bitnum(a) __builtin_popcount(a)using namespace std;const int N = 50005;const int M = 5005;const int inf = 1000000007;const int mod = 1000000007;__int64 Quick_Mod(int a, int b, int m){ __int64 res = 1,term = a % m; while(b) { if(b & 1) res = (res * term) % m; term = (term * term) % m; b >>= 1; } return res%m;}int main(){ int a,b; while(~scanf("%d%d",&a,&b)) printf("%I64d\n",Quick_Mod(a,b,10)); return 0;}菜鸟成长记
- HDU 1097 A hard puzzle && 快速幂
- HDU 1097 A hard puzzle(快速幂)
- HDU 1097 A hard puzzle【快速幂取模】
- hdu 1097 A hard puzzle (快速幂取模)
- HDU-1097-A hard puzzle( 快速幂取模 )
- hdu 1097 A hard puzzle(快速幂入门)
- HDU 1097 A hard puzzle(简单快速幂)
- HDU 1097 A hard puzzle(快速幂)
- HDU 1097 A hard puzzle(找规律,快速幂)
- HDU 1097 A hard puzzle (规律&&快速幂)
- HDU-1097-A hard puzzle(快速幂)
- hdu 1097 A hard puzzle 快速幂 找规律 H
- hdu 1097 A hard puzzle (快速幂)
- HDU--1097A hard puzzle(快速幂)
- hdu 1097 A hard puzzle
- hdu-1097 A hard puzzle
- HDU 1097 A Hard Puzzle
- HDU 1097 A hard puzzle
- CSS 中相对长度 rem 和 em 如何区别
- 积分获取规则
- 存储管理
- iOS图像处理(1)绘制简单的几何图形
- npm WARN For further explanations, please read (npm安装hexo错误解决)
- HDU 1097 A hard puzzle(快速幂)
- c++ primer读书笔记 4.11:类型转换
- XAMPP中Apache无法运行解决方法
- H5学习之16 CSS
- STVD+COSMIC编译工程时can't open file crtsi0.sm8
- 【日常收获4】Android4.0全屏实现
- UVA1588 UVALive3712 POJ3158 Kickdown
- 二叉查找树
- RandomAccessFile可实现数据的分段写入也就是多线程下载