【codeforces 742A】Arpa’s hard exam and Mehrdad’s naive cheat
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 second
typedef 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;
}
【codeforces 742A】Arpa’s hard exam and Mehrdad’s naive cheat的更多相关文章
- 【codeforces 742C】Arpa's loud Owf and Mehrdad's evil plan
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 742B】Arpa’s obvious problem and Mehrdad’s terrible solution
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【42.86%】【codeforces 742D】Arpa's weak amphitheater and Mehrdad's valuable Hoses
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- CodeForces 742A Arpa’s hard exam and Mehrdad’s naive cheat
题意:求1378 n次幂的最后一位. 析:两种方法,第一种,就是快速幂,第二种找循环节,也很好找,求一下前几个数就好. 代码如下: #pragma comment(linker, "/STA ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 534A】Exam
[题目链接]:http://codeforces.com/contest/534/problem/A [题意] 给你n个人,要求任意两个编号相邻的人不能相邻; 让你安排座位方案,使得最多人的可以入座 ...
- 【22.73%】【codeforces 606D】Lazy Student
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces Round】 #432 (Div. 2) 题解
Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) A. Arpa and a research in Mexi ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
随机推荐
- js17---创建对象:构造函数式和原型组合模式、动态原型模式、稳妥构造函数式
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- BZOJ2780: [Spoj]8093 Sevenk Love Oimaster(广义后缀自动机,Parent树,Dfs序)
Description Oimaster and sevenk love each other. But recently,sevenk heard that a girl named ChuYuXu ...
- x64系统下,InpOutx64有数字签名而WinIO3.0无数字签名
参考文档 http://www.highrez.co.uk/Downloads/InpOut32/ //可以下载InpOutx64的驱动程序及DLL,还有驱动主板硬件IO的例程 https://www ...
- swift -结构体
// // main.swift // Struct-Demo-05 // import Foundation println("结构体測试!") //结构体和C语言的结构体不同 ...
- 怎样将OpenStack部署到Hadoop
随着信息时代的快速发展,大数据技术和私有云环境都非常实用;只是,假设将两者结合在一起.企业会获得巨大的利润.虽然结合两者会让环境变得更复杂.企业仍然能够看到将 OpenStack 私有云和 Apach ...
- amazeui学习笔记一(开始使用3)--兼容性列表compatibility
amazeui学习笔记一(开始使用3)--兼容性列表compatibility 一.总结 1.不要用ie做前端测试,不要碰ie,尽量用google 浏览器: 按照微软官方的说法,IE 开发者工具中的浏 ...
- 3.实战HTML+CSS布局(实例入门篇)
转自:https://www.cnblogs.com/hmyprograming/archive/2012/03/23/2414373.html 学习这篇入门教程我们假定你已经具有了一定的HTML基础 ...
- JS搜索菜单实现
1 <!--菜单搜索功能--> 2 <!--先写静态页面--> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 ...
- Redfield Water Ripples 2.02(水波滤镜中文绿色版-支持CC)
Redfield Water Ripples 能够用于设计具有高度现实主义风格的水波纹特效,它提供了诸多属性选项,其 3D 渲染品质另人映像深刻.此滤镜很易用,其随机设定生成器可创建差点儿无限的水波纹 ...
- Altium Designer如何创建类,如何修改线宽
如果线宽还是没有改变,就是因为,有一个默认的class,它的规则优先级要高于PWR