【HDOJ】1061 Rightmost Digit
这道题目可以手工打表,也可以机器打表,千万不能暴力解,会TLE。
#include <stdio.h>
#define MAXNUM 1000000001
int buf[][];
int main() {
int case_n, n;
int i, j;
for (i=; i<; ++i) {
buf[i][] = ;
buf[i][] = i;
for (j=; j<; ++j) {
buf[i][j] = buf[i][j-]*i%;
if (buf[i][j] == buf[i][])
break;
buf[i][]++;
}
}
/*
for (i=0; i<10; ++i) {
printf("%d:", i);
for (j=1; j<=buf[i][0]; ++j)
printf(" %d", buf[i][j]);
printf("\n");
}
*/
scanf("%d", &case_n);
while (case_n--) {
scanf("%d", &n);
i = n % ;
j = n % buf[i][];
if (!j)
j = buf[i][];
printf("%d\n", buf[i][j]);
}
return ;
}
【HDOJ】1061 Rightmost Digit的更多相关文章
- HDU 1061 Rightmost Digit --- 快速幂取模
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...
- hdoj 1061 Rightmost Digit【快速幂求模】
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDOJ 1061 Rightmost Digit(循环问题)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- HDOJ 1061 Rightmost Digit
找出数学规律 原题: Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- 杭电 1061 Rightmost Digit计算N^N次方的最后一位
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- 题解报告:hdu 1061 Rightmost Digit(快速幂取模)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- 快速幂 HDU 1061 Rightmost Digit *
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 【HDOJ】1597 find the nth digit
二分. #include <stdio.h> #include <math.h> int main() { int case_n; double n, tmp, l, r; i ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
随机推荐
- Oracle存储过程学习使用
存储过程创建语法: create or replace procedure 存储过程名(param1 in type,param2 out type) as 变量1 类型(值范围); 变量2 类型(值 ...
- Java基础从数组到集合之间关键字的区别!!!!
1.&& 和 &区别和联系: 相同点 : 结果是一样的. 不同点 :如果使用双&号判断,如果说条件一为false,不会判断条件二,但是单&号会继续判 ...
- 牛客网算法题之All-in-All
题目: 有两个字符串s 和t,如果即从s 中删除一些字符,将剩余的字符连接起来,即可获得t.则称t是s 的子序列.请你开发一个程序,判断t是否是s的子序列. 输入描述: 输入包含多组数据,每组数据包含 ...
- nodejs学习[持续更新]
1.退出node process.exit(0) 2.把API从上往下全部看一遍,先混个眼熟. 3. end
- Qt-获取网络接口信息的综合示例
在前面的文章中介绍了与 获 取 本 机 网 络 信 息 相 关 的 类 常 用 的 有 4 个 , 分 别 是 : QHostAddress, QHostInfo, QNetworkInterface ...
- 栈(链式存储) C++模板实现
#include <iostream> using namespace std; //栈结点类 template <typename T> class stackNode{ p ...
- C# Form窗体子窗口关闭时刷新父窗体中的datagridview
解决该问题可以用委托,但是还有更简单方便的两种方法: 方法一:将主窗体实例保存到子窗体 show form2的时候设置一下 owner为form1 Form2 f2 = new Form2(); / ...
- HttpContext.Current多线程调用
1.在web网站的Global中,进行数据量比较大的初始化工作,而为了使用户在页面上能够及时响应,我们在Global中开启了一个线程执行该函数模块. 不过,在线程中用到HttpContext.Curr ...
- rm排除指定文件或指定文件夹下文件
3.方法3,当前文件夹中结合使用grep和xargs来处理文件名: ls | grep -v keep | xargs rm #删除keep文件之外的所有文件 说明: ls先得到当前的所有文件和文件夹 ...
- php开学之环境搭建
1. php版本选择 1.1 PHP非线程安全与线程安全版本的选择技巧 1.2 版本区别 PHP的大版本主要分三支:PHP4/PHP5/PHP6 其中,PHP4由于太古老.对QQ支持不力已基本被淘汰, ...