Rightmost Digit(最后一位数字)
Description
Input
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
Sample Input
Sample Output
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. 题目意思:
求n的n次方的最后一位数字
#include<stdio.h>
#include<string.h>
int main()
{
long long int n,i,j,ans,t,sum;;
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
sum=;
ans=;
n=n%;//找出规律,20个数一次循环
if(n==)
{
n=;
}//将范围缩小到20以内
for(i=;i<n;i++)
{
sum=ans*n;
ans=sum%;//(只要最后的一位)
}
ans=ans%;
printf("%lld\n",ans);
}
return ;
}
Rightmost Digit(最后一位数字)的更多相关文章
- 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 ...
- 杭电 1061 Rightmost Digit计算N^N次方的最后一位
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- Rightmost Digit (求n^n最后一位)
Description Given a positive integer N, you should output the most right digit of N^N. Input The ...
- <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字
1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...
- HDU 1061 Rightmost Digit --- 快速幂取模
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...
- HDOJ 1061 Rightmost Digit(循环问题)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- [Swift]LeetCode402. 移掉K位数字 | Remove K Digits
Given a non-negative integer num represented as a string, remove k digits from the number so that th ...
- HDOJ 1061 Rightmost Digit
找出数学规律 原题: Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
随机推荐
- .Net core 使用TimeJob
在我以前的文章中有一个.Net core使用Quartz.Net ,一开始我们的设想就是定时操作数据库,所以有很多实现方法,后来发现TimeJob可以同样实现我们的需求,而且更简便. 所以我们就使用了 ...
- DOM节点操作阶段性总结
HTML中能看到的所有东西都是dom树中的一个节点,注意是“所有”,使用childNodes()可以看到,回车(换行)也是一个节点. 从上图可以看到,select中有四个option,但是有9个节点. ...
- 同步请求和异步请求的区别(理解ajax用)
同步请求:发送方发送数据包后,等待接收方发回响应之后,才能发送下一个数据包的通信方式. 异步请求:发送方发送数据包后,不用等待接收方发回响应,就可以发送下一个数据包的通信方式. 同步通信:要求通信双方 ...
- 使用什么进行app开发
HTML5+plus, Hbuilder HTML5+plus介绍 HTML5 Plus移动App,简称5+App,是一种基于HTML.JS.CSS编写的运行于手机端的App,这种App可以通过扩展的 ...
- 对象转换成JSON字符串
定义一个Student类: 1 class Student { 2 public $name; 3 public $age; 4 function __construct($name, $age) { ...
- while do while switch语句的简要分析
1 //// while是C语言的一个关键字,其后是使用一个小括号中的条件表达式来做为执行循环的条件, 2 ////也就是说当条件表达式的结果为真时执行大括号里面的的程序内容, 3 ////而当条件表 ...
- golang使用rabbitMQ入门代码
package main import ( "github.com/streadway/amqp" "log" "time" ) func ...
- 16-oauth2-oidc-Client实现
1-新建.net core2.1 mvc网站 2-在Startup.config文件增加相关代码, 下面代码已经配置好oidc客户端了,并设置本mvc启动ip为5009 public void Con ...
- eclipse注释任务标记
一.概述 TODO: + 说明: 如果代码中有该标识,说明在标识处有功能代码待编写,待实现的功能在说明中会简略说明. FIXME: + 说明: 如果代码中有该标识,说明标识处代码需要修正,甚至代码是 ...
- 北京Uber优步司机奖励政策(1月3日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...