求n^k的前3位和后3位
来源:互联网 发布:淘宝网关键词排名查询 编辑:程序博客网 时间:2024/06/13 02:11
E - Leading and Trailing
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %lluSubmit Status Practice LightOJ 1282
Description
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 containing two integers: n (2 ≤ n < 231) and k (1 ≤ k ≤ 107).
Output
For each case, print the case number and the three leading digits (most significant) and three trailing digits (least significant). You can assume that the input is given such that nk contains at least six digits.
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
#include <iostream>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <cstdlib>#include <cstdio>#include <algorithm>using namespace std;typedef long long ll;int qpow(ll x,ll k,ll mod){ll ret = 1;ll mul = x;while(k > 0){if(k & 1){ret = (ret * mul) % mod;}mul = mul * mul % mod;k >>= 1;}return ret;}int main(){int T;scanf("%d",&T);int C = 1;while(T--){ll n,k;scanf("%lld%lld",&n,&k);int x = pow(10,2+k*log10(n)-int(k*log10(n)));int y = qpow(n,k,1000);printf("Case %d: %d %03d\n",C++,x,y);} return 0;}
0 0
- 求n^k的前3位和后3位
- UVa 11029 - Leading and Trailing 数学题(求n^k的前N位和后N位)
- 求a^b前n位和后n位
- UVa 11029 - Leading and Trailing 求n^k的前3位
- 已知一个整数n,求n^n的前k位
- lightoj 1282 求n^k的前面3位和后面三位
- 求m的n次方的后3位
- 求n^k的前三位数和后三位数
- k次方 求1个数的n次方的前三位数和后三位数
- LightOJ 1282 - Leading and Trailing (求n^k的前三位和后三位)
- light_oj 1282 求n^k的前几位数和后几位数
- 求n^k的前几位数和后几位数
- 求给定数组右移动k位后的数组
- 求f(k)=k^k(k=1...n)的前n项和
- 求N!的最高位
- 求n!的最高位
- 求n位的格雷码
- K次方(即求n^k的前三位与后三位)
- JAVA实现斐波那契数列问题(《剑指offer》)
- (void**)&a
- SCU 4438 Censor (字符串哈希)
- 四川省赛G.Party
- UVA 11292 Dragon of Loowater
- 求n^k的前3位和后3位
- 用递归判断一个数组是否递增 JAVA代码
- nyoj 一种排序 8 (结构体 排序)
- Android 事件处理详解(四) —— Handler和AsyncTask(补充)
- HDU5483求一个图中的最小生成树不能去掉的边的数目
- Spinner
- 对Oracle性能调优的基本方案
- web前端,实现上下翻页,支持鼠标滑动翻页h5+css+jq
- leetcode 242 :Valid Anagram