uva11029 - Leading and Trailing
题目:
求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 namespace std;
typedef long long ll;
const int INF = 1000000000;
#define MAX 200 int n, k; ll power_mod(ll a, ll n, ll mod)
{
if(n == 0) return 1LL;
ll ans = power_mod(a, n/2, mod);
ans = ans*ans%mod;
if(n%2) ans = ans*a%mod;
return ans;
} double pow(double a, int n)
{
if(n == 0) return 1;
double ans = pow(a, n/2);
ans = ans*ans;
if(n%2) ans = ans*a;
while( ans > INF ) ans /= INF;
return ans;
} int main()
{
// freopen("input.txt", "r", stdin);
int caseNum;
scanf("%d", &caseNum);
while(caseNum--)
{
scanf("%d %d", &n, &k);
double head = pow( (double)n, k );
char str[MAX];
sprintf(str, "%lf", 1000*head);
str[3] = '\0'; ll last = power_mod(n, k, 1000);
printf("%s...%03lld\n", str, last);
} return 0;
}
uva11029 - Leading and Trailing的更多相关文章
- UVA-11029 Leading and Trailing
Apart from the novice programmers, all others know that you can’t exactly represent numbers raised t ...
- [题解]UVA11029 Leading and Trailing
链接:http://vjudge.net/problem/viewProblem.action?id=19597 描述:求n^k的前三位数字和后三位数字 思路:题目要解决两个问题.后三位数字可以一边求 ...
- LightOJ 1282 Leading and Trailing (快数幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS Me ...
- 【LightOJ1282】Leading and Trailing(数论)
[LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(m ...
- Leading and Trailing (数论)
Leading and Trailing https://vjudge.net/contest/288520#problem/E You are given two integers: n and k ...
- Leading and Trailing(数论/n^k的前三位)题解
Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...
- E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。
/** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字, ...
- UVA 11029 || Lightoj 1282 Leading and Trailing 数学
Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...
- LightOJ1282 Leading and Trailing —— 指数转对数
题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing PDF (English) Statistics ...
随机推荐
- 安装sql server 2008 management studio时,提示升级VS2008 到 SP1
安装sql server 2008 management studio时,提示错误:此计算机上安装了 Microsoft Visual Studio 2008 的早期版本.请在安装 SQL Serve ...
- 解决在Linux下安装Oracle时的中文乱码问题
本帖最后由 TsengYia 于 2012-2-22 17:06 编辑 解决在Linux下安装Oracle时的中文乱码问题 操作系统:Red Hat Enterprise Linux 6.1数据库:O ...
- 2014年1月24日 Oracle 连接查询与子查询
1.乘积连接: 源表.源数据交叉链接,结果集数量为源数据之间的乘积 2.相等链接: 通过where关联几个数据源中的某一字段进行链接 3.自链接 自己链接自己 SSF A a1, A a2 ...
- org.springframework.beans.factory.BeanCreationException
org.springframework.beans.factory.BeanCreationException 这个是创建bean的异常. 我所遇到的情况是由下面这个引起的: @Resource an ...
- flash的as操作XML
//as3.0 var myXML:XML = new XML(); var XML_URL:String = "nav.config"; var myXMLURL:URLRequ ...
- Struts2注解学习1
这是开博的第一篇,我希望每天把我学到的东西记录下来,成为一个知识库,方便以后的学习和分享 在项目中看到用struts2注解来做,很方便,做了一个用户登录的例子 1.加载所需jar包 commons-f ...
- [汇编语言]-第五章[bx]和loop指令
1- [bx]和内存单元的描述 [0]表示内存单元, 他的偏移地址为0 mov ax,[0] 将一个内存单元的内容送入到ax.这个内存单元的长度为2字节(字单元),存放一个字,偏移地址为0,段地址在d ...
- jQuery图片懒加载lazyload插件
http://www.neoease.com/lazy-load-jquery-plugin-delay-load-image/ js 模板引擎
- MVC4商城项目一:框架设计
代码已托管在 https://code.csdn.net/denghao156/ktnmb_mvc4 先上图,设计模式参考:ddmvc4.codeplex.com 一.unintofwork 设计 ...
- alsa音频驱动科普第一课
做linux音频编程对alsa应该不陌生. 但是对于刚接触这块技术的同学来说是一件困难的事情.原因在于:网上关于alsa的资料太少了,特别国内的资料更是大部分重复.对于初学者来说特别苦恼. 由于笔者经 ...