题目:

  求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. MVC4中 jquery validate 不用submit方式验证表单或单个元素

    正确引入MVC4 jquery验证的相关文件 <script src="/Scripts/jquery-1.4.4.js"></script> <sc ...

  2. 阿里云RDS导入服务器数据库 XtraBackup

    如果是centos系统,默认会开启selinux 一定需关闭selinux 解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=dis ...

  3. Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent

    修改pom.xml文件,添加以下属性 <project> ... <properties> <project.build.sourceEncoding>UTF-8& ...

  4. Jquery如何获取控件ID

    l  1.#id     用法: $(”#myDiv”);    返回值  单个元素的组成的集合 说明: 这个就是直接选择html中的id=”myDiv” l  2.Element       用法: ...

  5. DevExpress中SearchLookUpEdit用法总结

    在前一个项目中用到了DevExpress,需要搜索某一个字段,来拉取出对应的相关信息,比来比去,发现SearchLookUpEdit的用户体验更好,但自己是个不折不扣的C#和DevExpress的初学 ...

  6. wpf中,一个简单的自定义treeview

    首先创建一个自定义控件,在里面定义好treeview的样式,将本来的三角形的图标变为加号的图标,并且添加节点之间的连线. <UserControl x:Class="TreeViewE ...

  7. Ribbon1: 在Office菜单中添加项目

    Office菜单就是应用程序窗口左上角的一个小的应用程序按钮,这个按钮被称作Office按钮,包含一些通用的操作或命令,例如打印.保存和发布.定制Office菜单时,其下的命令将影响整个文档,而不是文 ...

  8. 写sql语句注意事项

    做管理系统的,无论是bs结构的还是cs结构的,都不可避免的涉及到数据库表结构的设计,sql语句的编写等.因此在开发系统的时候,表结构设计是否合理,sql语句是否标准,写出的sql性能是否优化往往会成为 ...

  9. 开发网站相关知识html和javascript

    1.html 布局 https://github.com/bramstein/jlayout/ http://welcome.totheinter.net/columnizer-jquery-plug ...

  10. JSON之三:获取JSON文本并解释(以google的天气API为例)

    google提供了天气的api,以广州天气为例,地址为: http://api.openweathermap.org/data/2.5/weather?q=guangzhou 返回的结果为: {   ...