思路:

掐住最后一位,快速幂一发就好了

#include<cstdio>
#include <map>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std; typedef __int64 LL; int cal(int g,int x)
{
int ans=1;
while(g)
{
if(g%2)
ans=(ans*x)%10;
x=(x*x)%10;
g>>=1;
}
return ans%10;
} int main()
{
int n;
scanf("%d",&n);
int ans;
ans=cal(n,n%10);
printf("%d",ans);
return 0;
}

51nod 1004 【快速幂】的更多相关文章

  1. 51nod 1013快速幂 + 费马小定理

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 这是一个等比数列,所以先用求和公式,然后和3^(n+1)有关,有n ...

  2. 51nod 矩阵快速幂(模板题)

    1113 矩阵快速幂  基准时间限制:3 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 给出一个N * N的矩阵,其中的元素均为正整数.求这个矩阵的M次方.由于M次方的计算结果太大 ...

  3. 51Nod 1004 n^n的末位数字(日常复习快速幂,莫名的有毒,卡mod值)

    1004 n^n的末位数字 题目来源: Author Ignatius.L (Hdu 1061) 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 给出一个整数N,输出 ...

  4. 51nod 1113 矩阵快速幂

    题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...

  5. 51Nod 1046 A^B Mod C(日常复习快速幂)

    1046 A^B Mod C 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = ...

  6. 51nod 1835 - 完全图 - [dp][组合数公式][快速幂]

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1835 基准时间限制:1 秒 空间限制:131072 KB   ...

  7. 51nod 1013 3的幂的和 - 快速幂&除法取模

    题目地址:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 Konwledge Point: 快速幂:https:/ ...

  8. 快速幂取模模板 && 51nod 1013 3的幂的和

    #include <iostream> #include <cstdio> #include <cmath> #include <vector> #in ...

  9. 快速幂的类似问题(51Nod 1008 N的阶乘 mod P)

    下面我们来看一个容易让人蒙圈的问题:N的阶乘 mod P. 51Nod 1008 N的阶乘 mod P 看到这个可能有的人会想起快速幂,快速幂是N的M次方 mod P,这里可能你就要说你不会做了,其实 ...

随机推荐

  1. centos 7 -- Disk Requirements: At least 134MB more space needed on the / filesystem.

    用了幾年的centos7,今天執行yum update時,彈出一行有錯誤的提示:Disk Requirements:   At least 134MB more space needed on the ...

  2. [Tools] Convert SVG to a PDF in Node with PDFKit and SVG.js

    Given a epxress application and an svg template, we want to draw some text, date onto it and convert ...

  3. hdu3076ssworld VS DDD 概率dp

    //ssworld VS DDD 两个人有血量值 hp1 , hp2  //两人掷骰子得到每一点的概率已知 //ssword赢的概率 //dp[i][j]  表示有第一个人血量为i.第二个人的血量为j ...

  4. CocoaPods安装问题

    主要步骤: sudo gem install cocoapods pod setup 验证是否安装成功: pod search SDWebImage 常见问题: 1 sudo gem install ...

  5. MySQL远程访问时非常慢的解决方案

    服务器放在局域网内进行测试时,数据库的访问速度还是很快.但当服务器放到外网后,数据库的访问速度就变得非常慢. 后来在网上发现解决方法,my.cnf里面添加 [mysqld] skip-name-res ...

  6. Qt linux文件同步写入

    因为linux 系统机制问题,文件的创建和写入并不会直接写入硬盘.而是先写入缓存,当系统要关闭或须要时才写入硬盘.为防止突然掉电,应将缓存中的文件及时同步到硬盘上去. linux 下的sync 命令具 ...

  7. DBExecutor android 数据库框架

    https://github.com/eltld/DBExecutor android 数据库框架,sqlite database

  8. VB.NE总结

    VB.NET视频看完了.但台湾微软资深讲师的声音还回荡在我的脑海中啊.刚開始听两位老师的讲课那是一个纠 结.感觉不亚于听英语听力训练.后来看到王鹏同学转载的台湾计算机术语和大陆计算机术语的对比,我才明 ...

  9. 多媒体开发之---h264快速运动估计算法

    #include "stdio.h"#include "stdlib.h"#include "malloc.h"#include " ...

  10. JS中使用组合构造函数模式和原型模式

    创建自定义类型的最常见方式,就是组合使用构造函数模式与原型模式.构造函数模式用于定义实例属性,而原型模式用于定义方法和共享的属性. 结果,每个实例都会有自己的一份实例属性的副本,但同时又共享着对方法的 ...