LightOJ 1282】的更多相关文章

http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1282 Description You are given two integers: n and k, your task is t…
Leading and Trailing lightoj 链接:http://lightoj.com/volume_showproblem.php?problem=1282 uva 链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1970 题意:给定 n, k ,求 nk 的前3位和后三位的值. 思路:1.前 3 位:把 nk 转化为…
LightOJ - 1282 Leading and Trailing 题解 纵有疾风起 题目大意 题意:给你一个数n,让你求这个数的k次方的前三位和最后三位. \(2<=n<2^{31}\),\(1<=k<10^{7}\) 并且\(n^{k}\)至少有6位数 解题思路 这个题目需要解决两个问题 输出\(n^{k}\)的前三位 输出\(n^{k}\)的后三位 输出后三位 这个比较好解决,使用快速幂和模运算就能解决,这里不再详细介绍,看代码就行了. 输出前三位 这个比较麻烦,因为\(…
求n^k的前三位数字和后三位数字. 范围: n (2 ≤ n < 231) and k (1 ≤ k ≤ 107). 前三位: 设 n^k = x ---> lg(n^k)=lg(x) ---> klg(n)=lg(x) ---> x=10^(klgn).   因为求前三位,klgn大于2的整数部分可以舍弃.bit=floor(klgn-2), x=10^(klgn-bit). 后三位:快速幂模1000即可. 代码: #include <iostream> #inclu…
题目大意:求n^k的前三位数 和 后三位数. 题目思路:后三位数直接用快速幂取模就行了,前三位则有些小技巧: 对任意正数都有n=10^T(T可为小数),设T=x+y,则n=10^(x+y)=10^x*10^y,其中10^x为10的整倍数(x为整数确定数位长度),所以主要求出10^y的值. T=log10(n^k)=klog10(n),可以调用fmod函数求其小数部分即y值. #include<iostream> #include<algorithm> #include<cst…
/* 前三位 len=log10n^k(乘积的长度) len=klog10n n^k=x*10^(len-1) x=n^k/10^(len-1) log10x = k*log10n - (len-1) x=pow(10,k*log10n - (len-1)) 后三位 快速幂解决 */ #include<bits/stdc++.h> using namespace std; #define ll long long ll n,k,x; ll power(ll a,ll n){ ll res=;…
题意: 求n的k次方的前三位 和 后三位 ...刚开始用 Java的大数写的...果然超时... 好吧  这题用快速幂取模求后三位  然后用一个技巧求前三位 ...orz... 任何一个数n均可以表示为10a, 其中 a 可以为小数 那么nk 可以表示为10ak  , 令ak == x + y  (其中x为整数 y为小数)  所以 ak - x == y fmod(x,1)可以返回x的小数部分 所以y = fmod(ak,1) /*由于x是整数,那么很明显他是用来指定位数的,因为10x肯定是一个…
Leading and Trailing Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Submit Status Description You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits o…
题意:求 n^k 的前三位和后三位. 析:后三位,很简单就是快速幂,然后取模1000,注意要补0不全的话,对于前三位,先取10的对数,然后整数部分就是10000....,不用要,只要小数部分就好,然后取前三位. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #inc…
Leading and Trailing You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. Input Input starts with an integer T (≤ 1000), denoting the number of test cases. Each case st…