LightOj1282(阶乘前三位和后三位)
来源:互联网 发布:erp适合 软件行业 编辑:程序博客网 时间:2024/06/11 17:02
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 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).
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.
5
123456 1
123456 2
2 31
2 32
29 8751919
Case 1: 123 456
Case 2: 152 936
Case 3: 214 648
Case 4: 429 296
Case 5: 665 669
在hdu上已经做过类似一样的了 ,基本就是取对数加上快速幂就可以得出答案。
#include<stdio.h> #include<math.h> #define ll long long ll Mod(ll a,ll b,ll mod) { //快速幂算法 ll ans=1; if(!b) return 1; ans=Mod(a*a%mod,b/2,mod); if(b&1)ans=ans*a%mod; return ans; } int main() { int t,cont=0; scanf("%d",&t); while(t--){ ll n,k; scanf("%lld%lld",&n,&k); int strat=(int)pow(10.0,2.0+fmod(k*log10(n*1.0),1.0));//前三位 int end=(int)Mod(n,k,1000);//后三位 printf("Case %d: %d %lld\n",++cont,strat,end);// ll 输出就溢出! }//忽略了后三位的首位是 0 的情况 return 0; }
- LightOj1282(阶乘前三位和后三位)
- LightOJ 1282(求高次幂的前三位和后三位)
- LightOJ 1282 - Leading and Trailing (求n^k的前三位和后三位)
- Light oj 1282 (求一个数的前三位和后三位)
- Lightoj1282——Leading and Trailing(幂取模求前三位)
- LightOJ 1282 Leading and Trailing(n阶的前三位,后三位)
- lightoj 1282 Leading and Trailing(求n^k的前三位后三位)
- K次方(即求n^k的前三位与后三位)
- K次方(即求n^k的前三位与后三位)
- 神奇的数学公式。。。求《k次方》的前三位与后三位
- C语言之基本算法15—前三位和后三位都是完全平方数的六位完全平方数
- HDU 2035 后三位
- 小数点后三位
- UVA - 11029Leading and Trailing(快速幂取模取后三位 + log10()取前三位)
- Leading and Trailing (快速取模和数字取前三位)
- A^B取后三位
- LightOJ 1282 Leading and Trailing(n^k的高三位和低三位)
- 【Loj 1282 】 Leading and Trailing 【a^b 的前3位and后三位】
- Linux进程间通信(IPC)
- 网易2016实习研发工程师编程题——寻找第K大
- android app性能优化大汇总
- CSS中一些常用的字体
- Android逆向学习笔记---逆向腾讯2016游戏安全挑战赛Tencent2016A.apk
- LightOj1282(阶乘前三位和后三位)
- Treap 基本ADT
- android studio导入不同版本的android项目
- 第一份工作总结
- 从“-2”告警跟踪到的问题
- 二分查找
- android app性能优化大汇总(UI渲染性能优化)
- 对于php、mysql优化、angularjs的一些小感悟
- leetcode-504-Diameter of Binary Tree