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. [Twisted] transport和protocol解耦

    Twisted中transport和protocol完全解耦. 这样设计的优点: 1.不同的Protocol协议实现可以重用相同类型的transport. 2.方便测试:假如测试一个协议实现,可以使用 ...

  2. Javascript字符串拼接小技巧

    在Javascript中经常会遇到字符串的问题,但是如果要拼接的字符串过长就比较麻烦了. 如果是在一行的,可读性差不说,如果要换行的,会直接报错. 在此介绍几种Javascript拼接字符串的技巧. ...

  3. Java面向对象程序设计--与C++对比说明:系列2(类机制)

    1. Java中的包机制(Package): 1.1   Java容许将一系列的类组合到一个叫package的集合中.package机制是一种非常好的管理工作的方式并可以将你自己的工作和系统或第三方提 ...

  4. Burp Suite Walkthrough

    Burp Suite is one of the best tools available for web application testing. Its wide variety of featu ...

  5. 【转】关于C的未定义行为

    关于C的未定义行为 转自:http://www.guokr.com/blog/471312/ 对于C的初学者来说,被要求做下面的这种题目真的是脑残的不能再脑残的行为.但是很多C初级教程——居然都有这样 ...

  6. 【elasticsearch】(1)centos7 使用yum安装elasticsearch 2.X

    前言 elasticsearch(下面称为ES)是一个基于Lucene的搜索服务器(By 百度百科:查看).所以他需要java的环境即jdk,这里提供懒人一键安装方式 # yum install ja ...

  7. npm install express -g出错

    npm ERR! Windows_NT npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program ...

  8. >炫酷的计时器效果Canvas绘图与动画<

    >炫丽的计时器效果Canvas绘图与动画< 虽然我是学习java的,但是因为最近使用html5的关系,多学习了一下前端知识. 现在,我要介绍的计时器是十分炫酷的,使用画布完成. 喜欢htm ...

  9. 桂电在线-转变成bootstrap版2(记录学习bootstrap)

    下载bootstrap框架https://github.com/twbs/bootstrap 或者 http://getbootstrap.com/ 拷贝模板 修改基本模板 语言zh-cn,标题,描述 ...

  10. 【小结】有关mysql扩展库和mysqli扩展库的crud操作封装

    现阶段php如果要操作mysql数据库 php给我们提供了3套库 1.mysql扩展库   面向过程操作 2.mysqli扩展库  面向对象操作和面向过程操作并存  安全性和效率高于mysql扩展库 ...