LightOJ 1282 Leading and Trailing(取n^k的最高三位数字)
2016-05-27 02:16
537 查看
题目链接:
LightOJ 1282 Leading and Trailing
题意:
给出n和k求出n^k的高三位和低三位。
分析:
低三位别忘了%03d输出啊!
高三位取log瞎搞啊!
LightOJ 1282 Leading and Trailing
题意:
给出n和k求出n^k的高三位和低三位。
分析:
低三位别忘了%03d输出啊!
高三位取log瞎搞啊!
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <climits> #include <cmath> #include <ctime> #include <cassert> #define IOS ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; typedef long long ll; const ll mod = 1000; int T, cases = 0; ll high, low, n, k; ll quick_pow(ll a, ll b) { ll res = 1, tmp = a % mod; while(b){ if(b & 1) res = res * tmp % mod; tmp = tmp * tmp % mod; b >>= 1; } return res % mod; } int main() { scanf("%d", &T); while(T--){ scanf("%lld%lld", &n, &k); low = quick_pow(n, k); double t = 1.0 * k * log10(n * 1.0); ll m = (ll)(floor(t)); high = (ll)(pow(10.0, t - m + 2.0)); //high = (ll) pow(10.0, 2.0 + fmod(1.0 * k * log10(n * 1.0), 1)); printf("Case %d: %lld %03lld\n", ++cases, high, low); } return 0; }
相关文章推荐
- MySQL Server 日志
- MSSQL 2005 LOG备份webshell的方法
- 使用MySQL Slow Log来解决MySQL CPU占用高的问题
- 清理SQL Server 2008日志文件Cannot shrink log file 2 的解决方案
- Android系统开发中log的使用方法及简单的原理
- android杂记:C++文件的添加log方法分享
- 提取oralce当天的alert log的shell脚本代码
- mysql正确安全清空在线慢查询日志slow log的流程分享
- PHP error_log()将错误信息写入一个文件(定义和用法)
- Apache启动错误Permission denied: httpd: could not open error log file解决方法
- Android开发笔记之:Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)
- Android编程之基于Log演示一个activity生命周期实例详解
- PHP如何将log信息写入服务器中的log文件
- SQL Server中减小Log文件尺寸的方法分享
- Python中使用logging模块打印log日志详解
- python根据文件大小打log日志
- Android将应用调试log信息保存在SD卡的方法
- Hadoop配置常见Log错误指导
- BIND(三)—— DNS工具和BIND日志.md
- lumen配置日志daily模式