题目:

  求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. 矩阵经典题目六:poj 3070 Fibonacci

    http://poj.org/problem?id=3070 按已构造好的矩阵,那么该矩阵的n次方的右上角的数便是f[n]. #include <stdio.h> #include < ...

  2. [Redux] Generating Containers with connect() from React Redux (FooterLink)

    Code to be refactored: class FilterLink extends Component { componentDidMount() { const { store } = ...

  3. linux重要的标准目录和文件

    linux重要的标准目录和文件 / 根目录,所有其他文件在根文件系统的子目录下 /bin 基本命令的二进制文件,存放linux下常用的命令和工具 /boot 引导加载器的固有文件,linux就是从这里 ...

  4. Entity Framework排序

    public ActionResult Index() { using (ApplicationDbContext db = new ApplicationDbContext()) { //var l ...

  5. struts1:Struts的中央控制器

    在Struts框架中,有多个组件分担控制器的工作,它们分别是ActionServlet类,RequestProcessor类和Action类等,其中ActionServlet是Struts框架中的核心 ...

  6. 【Android】设备标识简介(imei imsi mac地址)

    IMEI: 1- 意义: 参考http://zh.wikipedia.org/zh-cn/IMEI  国际移动设备辨识码 ,共15位,和厂商,产地等有关. 2- 获取: 直接查看设备信息,设置-关于手 ...

  7. jquery 字符个数(数字字母长度记为1,中文记为2,超过长度自动截)

    <script type="text/javascript">  //返回val的字节长度  function getByteLen(val) {  var len = ...

  8. Angular中Controller之间的信息传递(第二种办法):$emit,$broadcast,$on

    $emit只能向parent controller传递event与data( $emit(name, args) ) $broadcast只能向child controller传递event与data ...

  9. windows系统npm如何升级自身

    其实使用npm升级各种插件是很方便的,比如我想升级express框架,使用如下命令 npm update express 如果你的express是全局安装,则 npm update -g expres ...

  10. PHP学习笔记13淘宝接口开发一例(tmall.items.discount.search),PHP

    程序设计,因为接口是有请求次数限制的,正式接口也只有2W次每天的请求次数,所以我们需要把从接口返回的数据缓存起来. 采用的接口是http://api.taobao.com/apidoc/api.htm ...