题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1097

分析:简单题,快速幂取模, 由于只要求输出最后一位,所以开始就可以直接mod10.

/*A hard puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33036 Accepted Submission(s): 11821 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
7 66
8 800 Sample Output
9
6 Author
eddy
*/
//快速幂取模
#include <cstdio>
#include <cstring>
int main()
{
int a, b;
while(~scanf("%d%d", &a, &b)){
a = a % ;
int cnt = ;
while(b > ){
if(b % == ) cnt = cnt*a%;
b = b/;
a = a*a%;
}
printf("%d\n", cnt);
}
return ;
}

hdu 1097 A hard puzzle 快速幂取模的更多相关文章

  1. 题解报告:hdu 1061 Rightmost Digit(快速幂取模)

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  2. HDU 1097.A hard puzzle-快速幂/取模

    快速幂: 代码: ll pow_mod(ll a,ll b){      ll ans=;      while(b){          ==){              ans=ans*a%mo ...

  3. HDU 1061 Rightmost Digit (快速幂取模)

    题意:给定一个数,求n^n的个位数. 析:很简单么,不就是快速幂么,取余10,所以不用说了,如果不会快速幂,这个题肯定是周期的, 找一下就OK了. 代码如下: #include <iostrea ...

  4. HDU 1061 Rightmost Digit --- 快速幂取模

    HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...

  5. HDU 1061.Rightmost Digit-规律题 or 快速幂取模

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)

    先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...

  7. 杭电 2817 A sequence of numbers【快速幂取模】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 解题思路:arithmetic or geometric sequences 是等差数列和等比数 ...

  8. 【转】C语言快速幂取模算法小结

    (转自:http://www.jb51.net/article/54947.htm) 本文实例汇总了C语言实现的快速幂取模算法,是比较常见的算法.分享给大家供大家参考之用.具体如下: 首先,所谓的快速 ...

  9. UVa 11582 (快速幂取模) Colossal Fibonacci Numbers!

    题意: 斐波那契数列f(0) = 0, f(1) = 1, f(n+2) = f(n+1) + f(n) (n ≥ 0) 输入a.b.n,求f(ab)%n 分析: 构造一个新数列F(i) = f(i) ...

随机推荐

  1. Net-SNMP V3协议 安装配置笔记(CentOS 6.3/5.6)

    注意:snmp V3,需要需要关闭selinux和防火墙: 关闭selinux方法: #vi /etc/selinux/config 将文件中的SELINUX="" 为 disab ...

  2. linux内核期中总结

    20135132陈雨鑫 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000  ...

  3. phpcms全站搜索

    这篇博客已经移至http://www.cnblogs.com/nuanai/p/8028562.html中~~~~~~

  4. 自定义视图(SpringMVC)

    一.首先理解视图的解析过程 1)请求处理方法执行完成后,最终返回一个 ModelAndView 对象. ModelAndView 对象,它包含了逻辑名(访问URL)和模型对象(javaBean数据)的 ...

  5. router使用以及vue的动画效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  6. let申明与const申明

    ES6新增了let命令,用来声明变时量. 它的用法类似于var 但是所声明的变量,只在let命令所在的代码块内有效. // for(let i = 0; i<10 ;i++ ){ console ...

  7. Windows环境搭建mysql服务器

    Windows环境搭建mysql服务器: 1.下载mysql-installer-community-5.7.3.0-m13.2063434697并安装  安装详细步骤>> 2.安装mys ...

  8. [转帖]TMD为你揭秘中国互联网下半场所有秘密

    https://www.iyiou.com/p/35099.html 李安说,<比利.林恩的中场战事>是“一个成长的故事”.中国互联网也行至中场,下半场如何走,成长的方向在哪里,成当下关键 ...

  9. Jquery ajax $getScript()和$getJSON和JSONP

  10. Node http和express和mysql

    const http = require("http");const express = require("express");const mysql = re ...