time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.

Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n.

Mehrdad has become quite confused and wants you to help him. Please help, although it’s a naive cheat.

Input
The single line of input contains one integer n (0  ≤  n  ≤  109).

Output
Print single integer — the last digit of 1378n.

Examples
input
1
output
8
input
2
output
4
Note
In the first example, last digit of 13781 = 1378 is 8.

In the second example, last digit of 13782 = 1378·1378 = 1898884 is 4.

【题目链接】:http://codeforces.com/problemset/problem/742/A

【题解】

快速幂取模;
把那个数用快速幂乘一下;乘的时候取个位数就好;

【完整代码】

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se secondtypedef pair<int,int> pii;
typedef pair<LL,LL> pll;void rel(LL &r)
{r = 0;char t = getchar();while (!isdigit(t) && t!='-') t = getchar();LL sign = 1;if (t == '-')sign = -1;while (!isdigit(t)) t = getchar();while (isdigit(t)) r = r * 10 + t - '0', t = getchar();r = r*sign;
}void rei(int &r)
{r = 0;char t = getchar();while (!isdigit(t)&&t!='-') t = getchar();int sign = 1;if (t == '-')sign = -1;while (!isdigit(t)) t = getchar();while (isdigit(t)) r = r * 10 + t - '0', t = getchar();r = r*sign;
}//const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);LL n;
LL ans = 1;void f(LL x)
{if (x==0)return;f(x>>1);ans = (ans * ans)%10;if (x&1)ans=(ans*1378)%10;
}int main()
{//freopen("F:\\rush.txt","r",stdin);cin>>n;if (n==0)puts("1");else{f(n);cout << ans << endl;}return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/7626859.html

【codeforces 742A】Arpa’s hard exam and Mehrdad’s naive cheat相关推荐

  1. Codeforces 742A Arpa’s hard exam and Mehrdad’s naive cheat 打表+水题

    A. Arpa's hard exam and Mehrdad's naive cheat time limit per test 1 second memory limit per test 256 ...

  2. 【Codeforces 741 B. Arpa's weak amphitheater and Mehrdad's 】+ 并查集 + 01背包

    B. Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit p ...

  3. codeforces 742A-Arpa’s hard exam and Mehrdad’s naive cheat 快速幂

    传送门 : CF 742A 题解 直接做8的快速幂, 因为模数是10 用周期做也可以, 不过我优化不到0ms- AC code /*adrui's submissionLanguage : C++Re ...

  4. 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

    题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...

  5. 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

    题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...

  6. 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

    题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...

  7. 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)

    题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...

  8. 【CodeForces 997C】Sky Full of Stars(组合计数)

    题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...

  9. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

最新文章

  1. 每日一道面试题(第7期)---Android补间动画与属性动画的区别
  2. QT绘制带有数据源的图表
  3. jQuery对Ajax的封装应用(三)
  4. 记GMIC 2014
  5. javascript md5加密算法
  6. 怎样设计访谈提纲_服务设计简史
  7. 为什么败者树的访问外存次数要比胜者树少_为什么说蒙地卡罗搜索树MCTS是AlphaZero的核心?[AlphaZero理论篇之三]...
  8. Photoshop插件-保存-转换sRGB-脚本开发-PS插件
  9. 图像匹配 | 论文与方法整理
  10. 框架设计--第十七章 SSM框架整合--习题答案
  11. php制作奥运五环颜色代表的洲,php趣味 - php 奥运五环
  12. 扒一扒那些叫欧拉的定理们(七)——欧拉线定理的证明
  13. 映象笔记导出到word
  14. 正则表达式判断用户昵称
  15. android listview中播放视频,支持全屏
  16. nginx代理ssh端口
  17. 苹果微信更新不了最新版本_微信,最新版本更新,为何要将字体变小
  18. 论文阅读之Arcface
  19. 奥沙利文:大师中的大师
  20. 【web】HTTP工作原理及应用

热门文章

  1. PostgreSQL数据库设置远程连接
  2. 假如有人把支付宝所有存储服务器炸了,我们在里边的钱是不是都丢了?
  3. 两难!到底用 Spring BeanUtils 还是 Apache BeanUtils?
  4. 硬核!尽量避免 BUG 手法
  5. 住手!!你不需要微服务!
  6. MongoDB 4.2 正式发布,支持分布式事务!
  7. 系统重构的10点经验总结
  8. 三分钟构建高性能 WebSocket 服务 | 超优雅的 SpringBoot 整合 Netty 方案
  9. JPA_登录校验Controller代码
  10. python3.8安装pygame_Python3.8安装Pygame教程步骤详解