题目:

  求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的更多相关文章

  1. UVA-11029 Leading and Trailing

    Apart from the novice programmers, all others know that you can’t exactly represent numbers raised t ...

  2. [题解]UVA11029 Leading and Trailing

    链接:http://vjudge.net/problem/viewProblem.action?id=19597 描述:求n^k的前三位数字和后三位数字 思路:题目要解决两个问题.后三位数字可以一边求 ...

  3. LightOJ 1282 Leading and Trailing (快数幂 + 数学)

    http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS     Me ...

  4. 【LightOJ1282】Leading and Trailing(数论)

    [LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(m ...

  5. Leading and Trailing (数论)

    Leading and Trailing https://vjudge.net/contest/288520#problem/E You are given two integers: n and k ...

  6. Leading and Trailing(数论/n^k的前三位)题解

    Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...

  7. E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。

    /** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字, ...

  8. 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 ...

  9. LightOJ1282 Leading and Trailing —— 指数转对数

    题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing    PDF (English) Statistics ...

随机推荐

  1. Codeforces 474D Flowers dp(水

    题目链接:点击打开链接 思路: 给定T k表示T组測试数据 每组case [l,r] 有2种物品a b.b物品必须k个连续出现 问摆成一排后物品长度在[l,r]之间的方法数 思路: dp[i] = d ...

  2. mysql、sqlServer、hsql、oracle、db2各数据库支持的字段类型与最大精度

  3. 反对网抄,没有规则可以创建目标"install" 靠谱解答

    在ubuntu下遇到这个问题,原因其实很简单,你不能用WINDWOS下的方法用图形方式打开,然后点了一下按扭"解压缩",生成了一个文件夹. 的确,这个文件夹看起来和正常的没有什么区 ...

  4. 关于JS 对象与JSON对象

    Js对象 格式 : //var dataStr = '{ code: 1, msg: "修改成功", read: 1 }'; 序列化字符串为js对象: var p = eval(& ...

  5. WIFI网络访问(一)

    一,WIFI 网卡有哪些状态? WIFI 总共有以下五个状态,实际就是一些整形常量: 1.   WIFI_STATE_DISABLED : WIFI 不能使用,其值是: 1 . 2.   WIFI_S ...

  6. JQ 动态添加节点

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. UIView的交换实现,子视图交替变换

    其中加了一些动画  2016-01-13 其中主要的方法有:Demo下载地址,Demo中有介绍:https://github.com/lizhaojie001/UIview.git

  8. 深入char、varchar、text和nchar、nvarchar、ntext的区别详解

    很多开发者进行数据库设计的时候往往并没有太多的考虑char, varchar类型,有的是根本就没注意,因为存储价格变得越来越便宜了,忘记了最开始的一些基本设计理论和原则,这点让我想到了现在的年轻人,大 ...

  9. mysql中,执行delete语句时出现Lock wait timeout exceeded问题

    问题描述: 当我插入一条记录时,在调用save方法的时候出现了异常(记录重复了),导致了后面的commit语句不能执行了.这时我在数据库中删除重复记录时发现该表已经被锁上了.即出现错误.但过了一会再次 ...

  10. asp.net实现伪静态遇到的问题

    之前在一次项目(asp.net网站)中要用到伪静态技术,实现的思路大致是这样的: 在全局配置文件Global.asax(普通的类可以通过实现IHttpModule来完成)中的Application_B ...