Rightmost Digit

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

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
 
快速幂的原理其实是同余定理 (a*b)%c=((a%c)*(a%c))%c的实现过程
#include<stdio.h>
#include<string.h>
int f(int x)
{
int ans=1;
int y=x;
x=x%10;
while(y)
{
if(y&1)
ans=(ans*x)%10;
y/=2;
x=(x*x)%10;
}
return ans;
}
int main()
{
int n,m,j,i,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%d\n",f(n));
}
return 0;
}

  

hdoj 1061 Rightmost Digit【快速幂求模】的更多相关文章

  1. HDU 1061 Rightmost Digit --- 快速幂取模

    HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...

  2. hdu 2065 "红色病毒"问题(快速幂求模)

    n=1  --> ans = 2 = 1*2 = 2^0(2^0+1) n=2  -->  ans = 6 = 2*3 = 2^1(2^1+1) n=3  -->  ans = 20 ...

  3. Rightmost Digit(快速幂+数学知识OR位运算) 分类: 数学 2015-07-03 14:56 4人阅读 评论(0) 收藏

    C - Rightmost Digit Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...

  4. NYOJ-676小明的求助,快速幂求模,快速幂核心代码;

    小明的求助 时间限制:2000 ms  |  内存限制:65535 KB 难度:2 描述 小明对数学很有兴趣,今天老师出了道作业题,让他求整数N的后M位,他瞬间感觉老师在作弄他,因为这是so easy ...

  5. HDOJ 1061 Rightmost Digit(循环问题)

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  6. HDOJ 1061 Rightmost Digit

    找出数学规律 原题: Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  7. 题解报告:hdu 1061 Rightmost Digit(快速幂取模)

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  8. HDU 1061.Rightmost Digit-规律题 or 快速幂取模

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. 九度OJ 1085 求root(N, k) -- 二分求幂及快速幂取模

    题目地址:http://ac.jobdu.com/problem.php?pid=1085 题目描述: N<k时,root(N,k) = N,否则,root(N,k) = root(N',k). ...

随机推荐

  1. O-C相关04:类方法的概述与定义和调用

    类方法的概述与定义和调用 1, 类方法的概述 类方法(class method)在其他编程语言中常常称为静态方法(例如 Java 或 C# 等). 与实例方法不同的是,类方法只需要使用类名即可调用, ...

  2. UVA10142/PC110108Australian Voting

    UVA10142/PC110108Australian Voting 10142 Australian Voting Accepted C++11 0.769 2014-02-11 05:01:20 ...

  3. macbook pro retina 编程字体推荐

    使用VS2010.VS2012.Qt Creator编译工具首推等宽字体,等宽字体中consolas. 首先大家都知道等宽对于编码来说的直观性不言而喻,其次retina屏幕的特殊性,整天用特别小的字体 ...

  4. 解决GDB输出Qt内置类型的显示问题

    自从GDB 7.0之后,就加入了Pretty-Printer的这个概念.简单理解就是他可以让你用Python写一串脚本,然后让gdb去读取这串脚本后,可以自由的输出由你想自己定义的格式.我们直接举个简 ...

  5. JS中的 this

    JS中的 this 变化多端,似乎难以捉摸,但实际上对 this 的解读,还是有一定规律的. 分析this,该如何下手呢?下面有一个函数 function show(){ alert(this); } ...

  6. new Image()的用途

    new Image()用途总结: 1.图片预加载      在做游戏时,为了使图片能快打开可以做预加载.      原理:创建image对象,将image对象的src分别指向需加载的图片地址,图片被请 ...

  7. php中的NOTICE 的错误解决方法

    PHP新手NOTICE错误,特此写给那些遇到和我一样错误的朋友.   刚学习PHP,不久 最近在整留言板,刚才遇到个问题. 页面中,好多类似 Notice: in D:\wamp\www\study\ ...

  8. Sublime Text 2中前端必备的常用插件

    Sublime Text 2安装的插件和所有预置的插件全部在Packages文件下,可以直接通过”preferences“—>”Browse Pakcages“来访问. Sublime Text ...

  9. 【pyhton】短路逻辑

    编程语言常用的逻辑if a and b:#如果a是false,那么跳过b的判断,结果直接falseif a or b:#如果a为true,那么跳过b的判断,直接true

  10. Qt动画与Qt坐标小记

    Qt动画 转载自: <http://jingyan.baidu.com/article/154b46315757b628ca8f4116.html> 和  <http://blog. ...