Codeforces Round #383 (Div. 2) A(快速幂取膜)
来源:互联网 发布:c语言 gbk转unicode 编辑:程序博客网 时间:2024/05/18 14:26
题目链接
题意:求1378^n的最后一位。
直接上快速幂模板
因为a^4=(a^2)*(a^2)。所以可得快速幂如果n是偶数先让底数相乘,奇数直接乘到结果上。加快运算速度
#include<stdio.h>#include<string.h>int f(int m,int n){ int b=1; while(n>0) { if(n%2==1) b=(b*m)%10; n/=2; m=(m*m)%10; } return b;}int main(){ int n; scanf("%d",&n); printf("%d\n",f(1378,n));}
0 0
- Codeforces Round #383 (Div. 2) A(快速幂取膜)
- Codeforces Round #383 (Div. 2)(A+B)
- Codeforces Round #383 (Div. 2) A
- Codeforces Round #383 (Div. 2) A
- 【Codeforces Round #383 (Div. 2)】 (A,B,C)
- Codeforces Round #383 (Div. 2) A. Arpa’s hard exam and Mehrdad’s naive cheat(快速幂水题)
- Codeforces Round #346 (Div. 2) -A. Round House(模拟)
- Codeforces Round #383 (Div. 1)A
- Codeforces Round #383 (Div. 2) A.Arpa’s hard exam and Mehrdad’s naive cheat【循环节/快速幂】
- 2Char (Codeforces Round #329 (Div. 2) A)
- Codeforces Round #114 (Div. 2 )A题
- Codeforces Round #221 (Div. 2) (Problem 376A~C)
- Codeforces Round #256 (Div. 2) A. Rewards(简单题)
- Codeforces Round #260 (Div. 2) A (贪心)
- Codeforces Round #260 (Div. 2) A. Laptops(简单题)
- Codeforces Round #260 (Div. 2)455A - Boredom (DP)
- Codeforces Round #107 (Div. 2) A(简单模拟)
- Codeforces Round #109 (Div. 2) A (简单模拟)
- Android学习之集成极光推送功能
- List
- 使用codeblocks编程运行时终端不能复制粘贴
- 【12月7日】类的初始化(二):构造器初始化
- MySQL5.7 binlog_group_commit_sync_delay对并发复制性能的影响
- Codeforces Round #383 (Div. 2) A(快速幂取膜)
- BZOJ4711: 小奇挖矿
- echarts的legend图例的显示与隐藏(legend图例进入页面显示的个数)
- 快速增加微信好友技巧
- PullToRefresh下拉刷新 加载更多 详解 +示例
- 2016-12-7 新版筛选法求素数
- CSS3 的 transition 和 animation
- RxJava—操作符(过滤、合并、转换)
- 关于同网段内主机之间通信细节