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 ...
 
随机推荐
- Ubuntu亮度无法调节或调节无法保存的问题
			
装了搜狗输入法之后,系统设置里面的很多软件都没有了.以前屏幕太亮在电源里面可以调节,现在不行了.没办法,只能找其他的办法了. 在网上查了很多资料,经自己的实验,找到了一个成功的方法. 首先进入 /sy ...
 - Oracle Enterprise linux 7 安装Oracle11gR2
			
一.修改主机名和IP地址: [root@localhost Desktop]# cat /etc/hosts127.0.0.1 localhost.localdomain localhost 192. ...
 - ubuntu系统分区方案
			
一.各文件及文件夹的定义 /bin:bin是binary(二进制)的缩写.存放必要的命令 存放增加的用户程序. /bin分区,存放标准系统实用程序./boot:这里存放的是启动LINUX时使用的一些核 ...
 - onvif规范的实现:成功实现ONVIF协议RTSP-Video-Stream与OnvifDeviceManager的视频对接
			
有了前几篇的基础,现在可以正式开始onvif的实现工作,其中一项非常重要的部分就是视频流的对接,即能够在符合onvif标准的监控客户端软件里接收到设备端NVT发来的RTSP视频流.这里,我所用的客户端 ...
 - WinForm常用代码
			
//ToolStripSplitButton是标准按钮和下拉按钮的组合,各自工作,但有联系,感觉上后者是没有向下箭头ToolStripDropDownButton:ToolStripDropDownB ...
 - 在SQL中修改数据库名称
			
假设SQL Server 2008中有个数据库test,现在要将其改名为zhy步骤:(1) 分离数据库:打开management studio,找到test数据库-->右键-->任务--& ...
 - Jq合成事件绑定
			
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
 - php中的短标签 太坑人了
			
今天配置了一个php页面去修改svn密码问题,结果调了半天,最后在Windows和 Linux的运行现象是不一样,运行结果更不一样了,关键是完全一模一样的代码. 最后发现是短标签引起的,Windows ...
 - 类 的重载(Overloads)与隐藏(Shadows)
			
我在上篇文章中讲解了类 的继承和重写,如果想要在派生类中重写基类了方法或函数,那首先基类必须要有用 Overridable 关键字的公开声明的方法或函数,这样,基类的派生类才能用 Overrides ...
 - C++在数组元素个数未知情况下声明数组
			
我们都从书上学习的方法,定义一个数组需要数组名.类型以及数组元素个数,一般定义必须明确元素的个数,否则无法通过编译. 1. int a[]; 2. int n; int a[n]; 就想上面这两种情况 ...