HDU1061-Rightmost Digit-规律题,快速幂
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 55522 Accepted Submission(s): 20987
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
#include<stdio.h>
typedef long long ll;
int main(){
int a[][]={{},{},{,,,},{,,,},{,},{},{},{,,,},{,,,},{,}};
ll m;
int n,i,h;
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%lld",&m);
h=m%;
if(h==||h==||h==||h==)
printf("%d",h);
else if(h==||h==)
printf("%d",a[h][m%]);
else
printf("%d",a[h][m%]);
printf("\n");
}
}
return ;
}
第二个,快速幂取模,代码:
#include<stdio.h>
typedef long long ll;
ll mod=1e5;
ll pow(ll a,ll b){
ll ans=;while(b!=){
if(b%==)
ans=ans*a%mod;
a=a*a%mod;
b=b/;
}
return ans;
}
int main(){
ll n,m,ans;
while(~scanf("%lld",&n)){
while(n--){
scanf("%lld",&m);
ans=pow(m,m)%;
printf("%lld\n",ans);
}
}
return ;
}
HDU1061-Rightmost Digit-规律题,快速幂的更多相关文章
- 2017ACM暑期多校联合训练 - Team 2 1006 HDU 6050 Funny Function (找规律 矩阵快速幂)
题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e ...
- (hdu 6030) Happy Necklace 找规律+矩阵快速幂
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6030 Problem Description Little Q wants to buy a nec ...
- HDU1061 - Rightmost Digit
Given a positive integer N, you should output the most right digit of N^N. Input The input contains ...
- [LOJ#162]模板题-快速幂2
<题目链接> 注意:这可能也是一道模板题. 注意2:$p=998224352$ 注意3:对于$100\%$的数据,$n\leq 5 \times 10^6$ 这个题很启发思路,如果直接快速 ...
- HDU - 6198 number number number(规律+矩阵快速幂)
题意:已知F0 = 0,F1 = 1,Fn = Fn - 1 + Fn - 2(n >= 2), 且若n=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤a,n为正数,则n为mj ...
- P2220 [HAOI2012]容易题(快速幂)
Describe 为了使得大家高兴,小Q特意出个自认为的简单题(easy)来满足大家,这道简单题是描述如下: 有一个数列A已知对于所有的A[i]都是1~n的自然数,并且知道对于一些A[i]不能取哪些值 ...
- HDU 1005 Number Sequence【斐波那契数列/循环节找规律/矩阵快速幂/求(A * f(n - 1) + B * f(n - 2)) mod 7】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- CodeForces 992C Nastya and a Wardrobe(规律、快速幂)
http://codeforces.com/problemset/problem/992/C 题意: 给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减 ...
- HDU 5793 A Boring Question ——(找规律,快速幂 + 求逆元)
参考博客:http://www.cnblogs.com/Sunshine-tcf/p/5737627.html. 说实话,官方博客的推导公式看不懂...只能按照别人一样打表找规律了...但是打表以后其 ...
- POJ 3641 Pseudoprime numbers (数论+快速幂)
题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...
随机推荐
- php iconv 函数参数的区别
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/57 用户输入:英特尔® 酷睿™ i7处理器大显身手 case1 ...
- 453. Minimum Moves to Equal Array Elements
Given anon-emptyinteger array of sizen, find the minimum number of moves required to make all array ...
- xamarin Android activity生命周期详解
学Xamarin我为什么要写这样一篇关于Android 的activity生命周期的文章 已经学Xamarin android有一段时间了,现在想起当初Xamarin也走了不少的弯路.当然Xamari ...
- 自动化测试辅助工具(Selenium IDE等)
本随表目录 Selenium IDE安装和使用 FireBug安装和使用 FirePath安装和使用 Selenium IDE安装 方式一:打开Firefox-->添加组件-->搜索出 ...
- mysql change master导致gtid丢失
change master导致gtid丢失从innobackupex恢复导致binlog的拉取位置会导致主备gtid不一致.此类错误通过构造空事务方式无法修复.此时就需要change master 方 ...
- Spring aop 注解参数说明
在spring AOP中,需要使用AspectJ的切点表达式语言来定义切点. 关于Spring AOP的AspectJ切点,最重要的一点是Spring仅支持AspectJ切点指示器(pointcut ...
- sql存储过程中使用 output
1.sql存储过程中使用 output CREATE PROCEDURE [dbo].[P_Max] @a int, -- 输入 @b int, -- 输入 @Returnc int output - ...
- 面向对象 初级版 (Preview) 未完
概述: 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数里,日后使用无需重复编写,直接调用韩顺即可. 面向对象: 对函数进行分类和封装,让开发'更快更强' 面向对象和面向过程的通 ...
- Python day 3 (3)
一:判断语句: 1 if 语句 : 2 或者if 语句 : else : 3 或者if 语句 : elif 语句 : else : 4注意:的使用,缩进一般用4个空格来完成. 二:input 语 ...
- Scrapy1.4爬取笑话网站数据,Python3.5+Django2.0构建笑话应用
Part1:需求简要描述 1.抓取http://www.jokeji.cn网站的笑话 2.以瀑布流方式显示 Part2:安装爬虫框架Scrapy1.4 1. 安装Scrapy1.4 E:\django ...