题意:给你 n 和 k ,让你求 n^k 的前三位和后三位 思路:后三位很简单,直接快速幂就好,重点在于如何求前三位,注意前导0 资料:求n^k的前m位 博客连接地址 代码: #include <iostream> #include <cmath> #include <cstdio> #include <algorithm> #define ll long long using namespace std; ll qmod(ll a,ll b,ll mod)…
题意: 求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肯定是一个…
/** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字,保证一定至少存在六位. 思路:后三位求法只要不断对1000取余就行了. 前三位求法: 对一个数x,他可以用科学计数法表示为10^r*a (r为次方,1<=a<10) 设:n^k = x = 10^r*a 两边取对数: k*log10(n) = log10(x) = r+log10(a); 令y =…
1282 - 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…
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 转化为…
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…
题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are given two integers: n and k, your task is to find the most significant three digits, and le…
题解:求一个数的次幂,然后输出前三位和后三位,后三位注意有前导0的情况. 后三位直接用快速幂取模求解. 前三位求得时候只需要稍微变形一下,可以把乘过的结果拆成用科学计数法,那么小数部分只有由前面决定,所以取前三位利用double来计算就可以了. #include <bits/stdc++.h> using namespace std; typedef long long ll; const int Mod = 1000; ll ppow(ll a, ll k) // 后三位 { ll ans…
LightOJ - 1282 Leading and Trailing 题解 纵有疾风起 题目大意 题意:给你一个数n,让你求这个数的k次方的前三位和最后三位. \(2<=n<2^{31}\),\(1<=k<10^{7}\) 并且\(n^{k}\)至少有6位数 解题思路 这个题目需要解决两个问题 输出\(n^{k}\)的前三位 输出\(n^{k}\)的后三位 输出后三位 这个比较好解决,使用快速幂和模运算就能解决,这里不再详细介绍,看代码就行了. 输出前三位 这个比较麻烦,因为\(…
题意:求 n^k 的前三位和后三位. 析:后三位,很简单就是快速幂,然后取模1000,注意要补0不全的话,对于前三位,先取10的对数,然后整数部分就是10000....,不用要,只要小数部分就好,然后取前三位. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #inc…
题意:求nk的前三位和后三位. 分析: 1.后三位快速幂取模,注意不足三位补前导零. 补前导零:假如nk为1234005,快速幂取模后,得到的数是5,因此输出要补前导零. 2.前三位: 令n=10a,则nk=10ak=10x+y,x为ak的整数部分,y为ak的小数部分. eg:n=19,k=4,则nk=130321, a=log10(n)=1.2787536009528289615363334757569 ak=5.1150144038113158461453339030277, 因此,x=5,…
题解:求n^k的前三位和后三位. 后三位直接快速幂对1000去余就可以了.前三位可以转换成浮点数来操作,也是用快速幂,我们只保留答案的前三位,当前值大于1000.0的话就除以10,直到结果小于等于1000.0. #include<bits/stdc++.h> using namespace std; typedef long long ll; ll ksm(ll a,ll b){ ll res=; while(b){ ) res=res*a%; a=a*a%; b>>=; } re…
NNNNN Time Limit: 2000/1000ms (Java/Others) Problem Description: 对于整数N,求N^N的前5位和后5位(1057题加强版) Input: 多组测试数据,每组测试数据输入为一个整数n(6 <= n <= 10^9),n为0时结束. Output: 对每组测试输出为两个整数a和b,由空格隔开,保留前后0,格式见样例. Sample Input: 6 10 110 1001 0 Sample Output: 46656 46656 10…
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…
[LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(mod \ 1000\)的值,要补前导零 第一问...就是搞笑的 依旧是快速幂 但是用double来算 每次中间值只要大于1000 直接除得小于1000就行了 不会就看代码把.. 这题就是搞笑的... #include<iostream> #include<cstdio> #includ…
Leading and Trailing https://vjudge.net/contest/288520#problem/E 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), den…
Apart from the novice programmers, all others know that you can’t exactly represent numbers raised to some high power. For example, the C function pow(125456, 455) can be represented in double datatype format, but you won’t get all the digits of the…
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…
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 starts with a line cont…
http://lightoj.com/volume_showproblem.php?problem=1282 题目大意: 求n的k次方的前三位和后三位数然后输出 后三位是用快速幂做的,我刚开始还是不会快速幂,后来慢慢理解了. 前三位求得比较厉害 我们可以吧n^k = a.bc * 10.0^m; k*log10(n)  = log10(a.bc) + m; m为k * lg(n)的整数部分,lg(a.bc)为k * lg(n)的小数部分; x = log10(a.bc) = k*log10(n)…
求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次方,然后将答案用前三位和最后三位表示. Sample Input 2 123456 1 123456 2 Sample Output 123...456 152...936 分析: 题目中其实有提示,用double来表示n的k次方,double神奇的地方在于能转化为string类型的字符串.用到了sprintf这个函数.代码: #include <cstdio> #include <iostream> #include <cstring> using…
题目大意:求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…
题面 给定两个数n,k 求n^k的前三位和最后三位 Input Input starts with an integer T (≤ 1000), denoting the number of test cases. Each case starts with a line containing two integers: n (2 ≤ n < 2^31) and k (1 ≤ k ≤ 10^7). Solution 后面一问是搞笑的 前面一问? 也是搞笑的,用double除成小于1的数算就好了…
Sample Input 5 123456 1 123456 2 2 31 2 32 29 8751919 Sample Output Case 1: 123 456 Case 2: 152 936 Case 3: 214 648 Case 4: 429 296 Case 5: 665 669 题意:求一个数n的k次方后的前三位与后三位.并且后三位要求控制格式. 思路:这道题后三位可以用快速幂求出来,前三位就要用到log了.先说一下怎么求n^k的前三位. 我先设10^p=n^k,同时取log10…
链接:http://vjudge.net/problem/viewProblem.action?id=19597 描述:求n^k的前三位数字和后三位数字 思路:题目要解决两个问题.后三位数字可以一边求高次幂一边取模,下面给出求前三位数字的方法. n^k = (10^lg n)^k = 10^(k*lg n) 为了描述方便,令X=n^k .则 lg X 的整数部分表示X有多少位.设整数部分为zs,小数部分为xs,则X=(10^zs)*(10^xs) . (10^zs)的形式就是100--,跟X的位…
求分数序列前N项和 #include <stdio.h> int main() { int i, n; double numerator, denominator, item, sum, swap; while (scanf("%d", &n) != EOF) { numerator = 2; denominator = 1; item = 0; sum = 0; for (i = 1; i <= n; i++) { item = numerator/deno…
求阶乘序列前N项和 #include <stdio.h> double fact(int n); int main() { int i, n; double item, sum; while (scanf("%d", &n) != EOF) { sum = 0; if (n <= 12) { for (i = 1; i <= n; i++) { item = fact(i); sum = sum + item; } } printf("%.0f…
求平方根序列前N项和 #include <stdio.h> #include <math.h> int main() { int i, n; double item, sum; while (scanf("%d", &n) != EOF) { sum = 0; for (i = 1; i <= n; i++) { item = sqrt(i); sum = sum+item; } printf("sum = %.2f\n", s…
求简单交错序列前N项和 #include <stdio.h> int main() { int denominator, flag, i, n; double item, sum; while (scanf("%d", &n) != EOF) { flag = 1; denominator = 1; sum = 0; for (i = 1; i <= n; i++) { item = flag*1.0/denominator; sum = sum+item;…