HDU 1060 1061求 n^n 最左边 最右边的数字
2012-08-09 23:20
274 查看
求最左边用log
m=n^n
log10(m)=nlog10(n)
m=10^(nlog10(n))
10的整数幂第一位是1,那么第一位的数字由小数部分决定
代码如下
求最右边的数字 整数快速幂 每次%10就ok了
m=n^n
log10(m)=nlog10(n)
m=10^(nlog10(n))
10的整数幂第一位是1,那么第一位的数字由小数部分决定
代码如下
#include<stdio.h> #include<math.h> int main() { int t; scanf("%d",&t); while(t--) { __int64 n,b; double a,c; int d; scanf("%I64d",&n); a=n*log10(n); b=(__int64)a; c=a-b; d=pow(10,c); printf("%d\n",d); } return 0; }
求最右边的数字 整数快速幂 每次%10就ok了
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int res=1; int x=n; for(;x;x>>=1) { if(x&1) res=(res*(n%10))%10; n=((n%10)*(n%10))%10; } printf("%d\n",res); } return 0; }
相关文章推荐
- HDOJ 1060 / HDOJ 1061/ HDOJ 1568 总结(如何求大数最左边最右边的数)
- (HDU1061||nefu783)&&nefu 66 求N^N的最右边和最左边的数
- 将一个数组中奇数放左边偶数放右边,不用考虑数字的相对位置
- hdu 1060 要求 N^N的最高位数字
- 输入框限制,条件是左边输入框输入的数字要小于右边输入框的值,两边输入框要为整型数字。
- ACM_HDU 1060+1061 leftmost or rightmost digit(数论)
- (hdu 1060 ,1061)求N^N的最高位和最低位(取对数,快速幂)
- hdu水题十道,提高鸟语能力~~ 1032 1029 1033 1036 1037 1038 1039 1047 1856 1060 1061
- hdu 1060 n^n的最左边的数
- 杭电5288如何查找一个数字的最左边因子和最右边因子的下标,先处理100以下的数字,100以上的数字则是sqrt(n)
- HDU 1061 (51Nod 1004 )n^n的末位数字
- 某数组里存在乱序的正负数字,要求将负数放到左边,正数放到右边,并且正负数的相对位置不改变
- 一个数组,找出其中具有这样一个特性的数字:1、比它左边的数都大2、比它右边的数都小
- 【hdu 1060】【求N^N最低位数字】
- 重新排列数组,使得数组左边的数字为奇数,数组右边的数字为偶数
- 最左/右边的数-hd1060/1061
- 字符串重新排序,数字字符移到右边,字母字符移到左边,保持字符在原字符串中的前后顺序不变
- 求左边数字减去右边数字的最大差-动态规划
- 将一个字符串中小于0的数字放到左边,大于0的数字放到右边
- HDU 1060 求N ^ N 的第一位数字 用log 降低位数