/**
题目:E - Leading and Trailing
链接:https://vjudge.net/contest/154246#problem/E
题意:求n^k得前三位数字以及后三位数字,保证一定至少存在六位。
思路:后三位求法只要不断对1000取余就行了。
前三位求法:
对一个数x,他可以用科学计数法表示为10^r*a (r为次方,1<=a<10)
设:n^k = x = 10^r*a
两边取对数: k*log10(n) = log10(x) = r+log10(a);
令y = k*log10(n); 因为r是整数,1<=a<10所以0<=log10(a)<1
所以log10(a)为y的小数部分;即log10(a) = y-(long long)y;
a = 10^(y-(long long)y);
最终结果为:(long long)(a*100)即为前三位;
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+;
///后三位
ll Least(ll n,ll k)
{
ll p = ;
while(k>){
if(k&) p = p*n%;
n = n*n%;
k >>= ;
}
return p;
}
///前三位
ll Leading(ll n,ll k)
{
double y = k*log10(n);
double a = pow(10.0,y-(ll)y);
return (ll)(a*);
}
int main()
{
int T, cas=;
ll n, k;
cin>>T;
while(T--){
scanf("%lld%lld",&n,&k);
///注意这里后三位要输出三位。
printf("Case %d: %lld %03lld\n",cas++,Leading(n,k),Least(n,k));
}
return ;
}

E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。的更多相关文章

  1. 1282 - Leading and Trailing 求n^k的前三位和后三位。

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

  2. Uva 11029 Leading and Trailing (求n^k前3位和后3位)

    题意:给你 n 和 k ,让你求 n^k 的前三位和后三位 思路:后三位很简单,直接快速幂就好,重点在于如何求前三位,注意前导0 资料:求n^k的前m位 博客连接地址 代码: #include < ...

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

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

  4. UVA-11029 Leading and Trailing

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

  5. 1282 - Leading and Trailing ---LightOj1282(快速幂 + 数学)

    http://lightoj.com/volume_showproblem.php?problem=1282 题目大意: 求n的k次方的前三位和后三位数然后输出 后三位是用快速幂做的,我刚开始还是不会 ...

  6. LightOj 1282 Leading and Trailing

    求n^k的前三位数字和后三位数字. 范围: n (2 ≤ n < 231) and k (1 ≤ k ≤ 107). 前三位: 设 n^k = x ---> lg(n^k)=lg(x) - ...

  7. Leading and Trailing(巧妙利用log解决次方问题)

    Sample Input 5 123456 1 123456 2 2 31 2 32 29 8751919 Sample Output Case 1: 123 456 Case 2: 152 936 ...

  8. [题解]UVA11029 Leading and Trailing

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

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

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

随机推荐

  1. ueditor .net配置

    ASP.NET发展时期曾经诞生过 website  webapplication 两类程序. website 目前基本绝迹,就是曾经在App_Code目录中写代码,然后直接发布源码,动态编译的那种,基 ...

  2. SQLSERVER WINDBG调试:mssqlwiki.com

    https://mssqlwiki.com/2012/10/16/sql-server-exception_access_violation-and-sql-server-assertion/ SQL ...

  3. 取代Promise的Generator生成器函数

    接触过Ajax请求的会遇到过异步调用的问题,为了保证调用顺序的正确性,一般我们会在回调函数中调用,也有用到一些新的解决方案如Promise相关的技术. 在异步编程中,还有一种常用的解决方案,它就是Ge ...

  4. javascript:使用代理绑定事件

    <ul id="box"> <li>1</li> <li>2</li> <li>3</li> & ...

  5. 设置html属性为disabled时flask后台获取数据失败

    标签input的值如果不需要用户修改,则设置属性为 readonly,不要设置为 disabled.因为设置disabled会导致flask后端获取不到这个input得value rule_maker ...

  6. XPath注入技术综述

    一次完整的 XPath 注入攻击应该包括使用特殊构造的查询来提取一个 XML 数据库内的 数据或者信息.作为一门新的技术,XPath 注入在一定程度上和 SQL 注入漏洞有着惊人的相 似之处,通过下面 ...

  7. 我使用过的Linux命令之swig - 把C/C++的代码嵌入Java等语言的开发工具

    用途说明 SWIG是Simplified Wrapper and Interface Generator的缩写,其官方站点是http://www.swig.org/.SWIG是个帮助使用C或者C++编 ...

  8. 数据挖掘算法之聚类分析(二)canopy算法

    canopy是聚类算法的一种实现 它是一种快速,简单,但是不太准确的聚类算法 canopy通过两个人为确定的阈值t1,t2来对数据进行计算,可以达到将一堆混乱的数据分类成有一定规则的n个数据堆 由于c ...

  9. Python3环境安装Scrapy爬虫框架过程及常见错误

    收录待用,修改转载已取得腾讯云授权 Scrapy安装介绍 Scrapy的安装有多种方式,它支持Python2.7版本及以上或Python3.3版本及以上.下面说明Python3环境下的安装过程. Sc ...

  10. Scala 将BigDecimal转换为Long

    待转换.asInstanceOf[Number].longValue (Double转为Long也适用)