日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【codeforces 742A】Arpa’s hard exam and Mehrdad’s naive cheat

發布時間:2025/3/21 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。