HDU 1061
#include<stdio.h>
#include<string.h>
int a[10];
int main()
{
int T,n,i,k,temp,b,t;
scanf("%d",&T);
while(T--)
{
memset(a,0,sizeof(a));
scanf("%d",&n);
t = n;
n %= 10;
if(n==1||n==0)
{
printf("%d\n",n);
continue ;
}
temp = 0;
b = n;
i = 0;
while(temp!=n)
{
a[i++] = b;
temp = (b*n)%10;
b = temp;
}
k = t%i==0?i-1:t%i-1;
printf("%d\n",a[k]);
}
return 0;
}
#include<string.h>
int a[10];
int main()
{
int T,n,i,k,temp,b,t;
scanf("%d",&T);
while(T--)
{
memset(a,0,sizeof(a));
scanf("%d",&n);
t = n;
n %= 10;
if(n==1||n==0)
{
printf("%d\n",n);
continue ;
}
temp = 0;
b = n;
i = 0;
while(temp!=n)
{
a[i++] = b;
temp = (b*n)%10;
b = temp;
}
k = t%i==0?i-1:t%i-1;
printf("%d\n",a[k]);
}
return 0;
}
HDU 1061的更多相关文章
- HDU 1061 Rightmost Digit --- 快速幂取模
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...
- HDU 1061 N^N (n的n次方的最后一位)
题目意思: http://acm.hdu.edu.cn/showproblem.php?pid=1061 求N^N的最后一位数. 题目分析: 此题有非常多种方法,主要是中循环节,看自己怎么找了.我的方 ...
- hdu 1061 快速幂
求n^n的个位 Sample Input 2 3 4 Sample Output 7 6 直接快速幂了,注意要用long long #include<cstdio> long long q ...
- hdu 1061 Rightmost Digit
解决本题使用数学中的快速幂取余: 该方法总结挺好的:具体参考http://www.cnblogs.com/PegasusWang/archive/2013/03/13/2958150.html #in ...
- HDU 1061 Rightmost Digit解决问题的方法
求大量N^N的值最右边的数字,即最低位. 它将能够解决一个简单二分法. 只是要注意溢出,只要把N % 10之后.我不会溢出,代替使用的long long. #include <stdio.h&g ...
- HDU 1061 Rightmost Digit (快速幂取模)
题意:给定一个数,求n^n的个位数. 析:很简单么,不就是快速幂么,取余10,所以不用说了,如果不会快速幂,这个题肯定是周期的, 找一下就OK了. 代码如下: #include <iostrea ...
- HDU 1061.Rightmost Digit-规律题 or 快速幂取模
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 题解报告:hdu 1061 Rightmost Digit(快速幂取模)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- HDU 1061 EASY
//回宿舍去了,明天做点难一点的题,今天做的都很水,感觉.没意思.#include <iostream> #include <cstdio> using namespace s ...
随机推荐
- Swift 学习笔记1
最近在看Swift,努力在看相关的文档以及书籍,因为Swift3.0的更新,以及它开源了,所以打算写一些关于Swift的相关文章.让Swift能够更好的被我理解
- yii2 model常用验证规则
//字段必填[['username'],'required','message'=>'{attribute}不能为空!'][['username','password'], 'required' ...
- MySQL基础学习之数据表
查看数据表 SHOW TABLE; 查看数据表详细结构 SHOW CREATE TABLE 表名\G; 创建数据表 CREATE TABLE 表名(数据名 类型,数据名1 类型2); CREATE ...
- Android开发中activity切换动画的实现
(1)我们在MainAcitvity中定义两个textview,用于点击触发切换Activity事件,下面是布局文件代码. <LinearLayout android:layout_width= ...
- IntelliJ IDEA 14.x 创建工作空间与多个Java Web项目
以往的Eclipse.NetBeans等开发工具不同,IDEA的Project相当与Eclipse的Workspace,而Module相当于Project. 下边就给出Eclipse与IDEA的概念的 ...
- web2py--------------用web2py写 django的例子 --------开发环境
我们先从广为人知的例子说起xi 也就是官方的例子,我会在最后给出代码: ============================环境=================== 编译器使用vs code , ...
- 021,lambda 表达式
021,lambda 表达式 匿名函数: 快速定义单行的最小函数,是从lisp借用来的,可以用在任何需要函数的地方 >>> def ds(x): return 2*x + ...
- 宅男福利--利用Python简单爬图
Ver beta..代码粗陋. 使用说明以Windows为例, Python版本为2.7.6 确认你电脑已经安装了Python, Windows默认安装路径为C:\Python27.如果没有安装,先下 ...
- iOS runloop 资源汇总-b
RunLoop 是 iOS 和 OSX 开发中非常基础的一个概念,这篇文章将从 CFRunLoop 的源码入手,介绍 RunLoop 的概念以及底层实现原理.之后会介绍一下在 iOS 中,苹果是如何利 ...
- user is not mapped
用Hibernate实现一个用户的登陆过程,当我在JSP的登陆页面输入姓名和密码,点登陆后,显示登陆失败页,在服务器里显示如下的错误信息: org.hibernate.hql.ast.QuerySy ...