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 ...
随机推荐
- CentOS7.5二进制安装MySQL-5.6.40
安装依赖 yum install -y gcc gcc-c++ automake autoconf yum -y install cmake bison-devel ncurses-devel lib ...
- PHP 获取客户端 IP 地址
先来了解一个变量的含义: $_SERVER['REMOTE_ADDR']:浏览当前页面的用户计算机的ip地址 $_SERVER['HTTP_CLIENT_IP']:客户端的ip $_SERVER['H ...
- STM32 硬件UART接收超时检测设置
STM32 硬件UART接收超时检测设置 -----------------本文作者"智御电子",期待与电子爱好者交流学习.---------------- 应用场景 在uart应 ...
- JAVA基础 - 自定义异常类
自定义异常类,代码还不是很明白,先存着以后参考. package week6; class ScoreException extends Exception { private static fina ...
- java 写一个单例设计程序,打印出该对象的地址
class Test{ public static void main(String[] args) { singleton s1=singleton.getinstance(); singleton ...
- Log4net 配置实例
首先需要下载并引用Log4net的binary.这一步可以通过在Visual Studio里的Manage Nuget package for solution轻松添加. 第二步是配置config文件 ...
- MySQL入门第三天(下)——存储过程与存储引擎
一.存储过程 1.简介 原始的SQL执行的流程: 通过存储过程,便可以简化以上流程,那么存储过程是什么,如何进行性能提高呢? 是什么? 存储过程是可编程的函数,在数据库中创建并保存,可以由SQL语句和 ...
- 北京Uber优步司机奖励政策(1月23日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 成都Uber优步司机奖励政策(1月18日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- VINS(七)estimator_node 数据对齐 imu预积分 vision
首先通过vins_estimator mode监听几个Topic(频率2000Hz),将imu数据,feature数据,raw_image数据(用于回环检测)通过各自的回调函数封装起来 ros::Su ...