Uva 11029 Leading and Trailing (求n^k前3位和后3位)
题意:给你 n 和 k ,让你求 n^k 的前三位和后三位
思路:后三位很简单,直接快速幂就好,重点在于如何求前三位,注意前导0
资料:求n^k的前m位 博客连接地址
代码:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std; ll qmod(ll a,ll b,ll mod)
{
ll ans=;
while(b)
{
if(b%)
{
ans=(ans*a)%mod;
}
b=b/;
a=(a*a)%mod;
}
return ans;
} int main()
{
int t;
cin>>t;
while(t--)
{
ll n,k;
scanf("%lld %lld",&n,&k);
double a=k*log10((double)n);
a=a-floor(a);
double ans1 = pow(,a)*;
ll ans2 = qmod(n,k,);
cout<<(ll)ans1<<"...";
printf("%03lld\n",ans2);
}
return ;
}
Uva 11029 Leading and Trailing (求n^k前3位和后3位)的更多相关文章
- Leading and Trailing LightOJ - 1282 (取数的前三位和后三位)
题意: 求n的k次方的前三位 和 后三位 ...刚开始用 Java的大数写的...果然超时... 好吧 这题用快速幂取模求后三位 然后用一个技巧求前三位 ...orz... 任何一个数n均可以表示 ...
- E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。
/** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字, ...
- 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 ...
- lightoj 1282 && uva 11029
Leading and Trailing lightoj 链接:http://lightoj.com/volume_showproblem.php?problem=1282 uva 链接:http:/ ...
- LightOJ 1282 Leading and Trailing (快数幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS Me ...
- LightOJ1282 Leading and Trailing —— 指数转对数
题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing PDF (English) Statistics ...
- Leading and Trailing(LightOJ - 1282)
题解:求一个数的次幂,然后输出前三位和后三位,后三位注意有前导0的情况. 后三位直接用快速幂取模求解. 前三位求得时候只需要稍微变形一下,可以把乘过的结果拆成用科学计数法,那么小数部分只有由前面决定, ...
- Leading and Trailing LightOJ - 1282 题解
LightOJ - 1282 Leading and Trailing 题解 纵有疾风起 题目大意 题意:给你一个数n,让你求这个数的k次方的前三位和最后三位. \(2<=n<2^{31} ...
- LightOJ 1282 Leading and Trailing (数学)
题意:求 n^k 的前三位和后三位. 析:后三位,很简单就是快速幂,然后取模1000,注意要补0不全的话,对于前三位,先取10的对数,然后整数部分就是10000....,不用要,只要小数部分就好,然后 ...
随机推荐
- 获取元素最终的background-color
通常我们都会先获取元素,然后得到style对象获取对应的css属性值: 下面,假设我定义一个div并在css中给定了指定的background-color: 这里并没有考虑!important/内联的 ...
- jiayuan
8.2=http://files.cnblogs.com/files/bqh10086/jiayuan8.2pack.zip
- 【openstack N版】——块存储服务cinder
一.块存储服务介绍 1.1块存储服务通常包含以下组件 cinder-api: 接受API请求,并将其路由到"cinder-volume"执行. cinder-volume: 与块存 ...
- Java(基础)的类与变量
Java的类与成员变量 在我们学习编程语言中,需要灵活自用,那么怎么来灵活的将所有的函数属性来调用来实现完整的工程呢? 所以我们需要认识到类和变量的定义 1.类是什么? 类是抽象的概念,而对象就是类的 ...
- jquery 中时间的运用
运用Moment插件比较方面,有兴趣可以仔细阅读 http://momentjs.cn/
- Selenium 显示等待和隐式等待
1. 设置显示等待 Java代码: 1 2 3 4 5 public static WebElement WaitForElement(WebDriver driver, String locator ...
- Selenium 切换句柄
最近用了网络上别人的一段切换窗口的code每次成功了,不错,学习 // 根据Title切换新窗口 public boolean switchToWindow_Title(WebDriver drive ...
- CAEmitterLayer 粒子效果(发射器)
//创建Layer CAEmitterLayer *emitterLayer = [CAEmitterLayer layer]; //边框 emitterLayer.borderWidth = 1.0 ...
- H5 Video + DOM
HTML 5 Video + DOM HTML5 视频 HTML5 音频 HTML5 <video> - 使用 DOM 进行控制 HTML5 <video> 元素同样拥有方法. ...
- Spring Data JPA 简单查询--接口方法
一.接口方法整理速查 下表针对于简单查询,即JpaRepository接口(继承了CrudRepository接口.PagingAndSortingRepository接口)中的可访问方法进行整理.( ...