Rightmost Digit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 55522    Accepted Submission(s): 20987

Problem Description
Given a positive integer N, you should output the most right digit of N^N.
 
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
 
Output
For each test case, you should output the rightmost digit of N^N.
 
Sample Input
2
3
4
 
Sample Output
7
6

Hint

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-规律题,快速幂的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 2 1006 HDU 6050 Funny Function (找规律 矩阵快速幂)

    题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e ...

  2. (hdu 6030) Happy Necklace 找规律+矩阵快速幂

    题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6030 Problem Description Little Q wants to buy a nec ...

  3. HDU1061 - Rightmost Digit

    Given a positive integer N, you should output the most right digit of N^N. Input The input contains ...

  4. [LOJ#162]模板题-快速幂2

    <题目链接> 注意:这可能也是一道模板题. 注意2:$p=998224352$ 注意3:对于$100\%$的数据,$n\leq 5 \times 10^6$ 这个题很启发思路,如果直接快速 ...

  5. 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 ...

  6. P2220 [HAOI2012]容易题(快速幂)

    Describe 为了使得大家高兴,小Q特意出个自认为的简单题(easy)来满足大家,这道简单题是描述如下: 有一个数列A已知对于所有的A[i]都是1~n的自然数,并且知道对于一些A[i]不能取哪些值 ...

  7. 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 ...

  8. CodeForces 992C Nastya and a Wardrobe(规律、快速幂)

    http://codeforces.com/problemset/problem/992/C 题意: 给你两个数x,k,k代表有k+1个月,x每个月可以增长一倍,增长后的下一个月开始时x有50%几率减 ...

  9. HDU 5793 A Boring Question ——(找规律,快速幂 + 求逆元)

    参考博客:http://www.cnblogs.com/Sunshine-tcf/p/5737627.html. 说实话,官方博客的推导公式看不懂...只能按照别人一样打表找规律了...但是打表以后其 ...

  10. POJ 3641 Pseudoprime numbers (数论+快速幂)

    题目链接:POJ 3641 Description Fermat's theorem states that for any prime number p and for any integer a ...

随机推荐

  1. 瞎j8封装第二版之用xml文件来代理dao接口

    也是重新整理了之前的那篇 模仿Mybatis用map per.xml实现Dao层接口的功能 话不多说直接上代码 首先是结构 依赖pom.xml <?xml version="1.0&q ...

  2. 520. Detect Capital

      Given a word, you need to judge whether the usage of capitals in it is right or not. We define the ...

  3. ArcGIS 网络分析[4] 网络数据集深入浅出之连通性、网络数据集的属性及转弯要素

    前面介绍完了如何创建网络数据集.如何使用网络分析功能,当然还有的读者会迷惑于一些更深层次的问题,比如网络数据集的连通性问题等. 因为不可能面面俱到,我只能挑重点来阐述,我觉得网络数据集的连通性.属性和 ...

  4. thinkphp3.2.3的使用心得(零)

    从模板传参到控制器 模板中代码: <volist name="list" id="vo"> <a href="__CONTROLLE ...

  5. vim编辑器的使用技巧

    vim(vi)是上Linux非常常用的编辑器,很多Linux发行版都默认安装了vi(vim).vi(vim)命令繁多但是如果使用灵活之后将会大大提高效率.vi是“visual interface”的缩 ...

  6. 封装简单的equery

    /** * Created by wang on 2016/3/23. */ //绑定操作 function bindEvent(obj,events,fn){ if (obj.addEventLis ...

  7. class, classloder, dex 详解

    class与dex文件 什么是class文件 class文件是一种能够被JVM识别,加载并且执行的文件格式. class文件的作用 class文件的作用是记录一个类文件的所有信息. 例如记住了当前类的 ...

  8. 微信小程序之使用本地接口开发

    本文主要讲解如何使用本地接口进行开发,很多人都会遇到这个问题,特别是小程序上线后. 一.解决思路 在小程序开发工具设置网络代理,然后再通过Charles设置代理,将https域名转为本地接口进行访问. ...

  9. sql server 权限

    -----是否存在有效的登录账号:是否被禁用,sql login还有:密码是否过期,是否被锁定 select is_disabled, loginproperty(name,'Isexpired') ...

  10. StringMVC @RequestParam属性

    1.jsp: <a href="springmvc/testRequestParam?username=allen&age=sss">test RequsetP ...