【LightOJ1282】Leading and Trailing(数论)
【LightOJ1282】Leading and Trailing(数论)
题面
Vjudge
给定两个数n,k 求n^k的前三位和最后三位
题解
这题。。真的就是搞笑的
第二问,直接输出快速幂\(mod \ 1000\)的值,要补前导零
第一问。。。就是搞笑的
依旧是快速幂
但是用double来算
每次中间值只要大于1000
直接除得小于1000就行了
不会就看代码把。。
这题就是搞笑的。。。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
inline int read()
{
int x=0,t=1;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=-1,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return x*t;
}
int n,k,T;
int fpow(int a,int b)
{
a%=1000;int s=1;
while(b){if(b&1)s=a*s%1000;a=a*a%1000;b>>=1;}
return s;
}
void write(int x)
{
int kk[5];
for(int i=1;i<=3;++i)kk[i]=x%10,x/=10;
for(int i=3;i;--i)printf("%d",kk[i]);
}
double ppp(double a,int b)
{
double s=1;
while(b)
{
if(b&1)s=s*a;
a=a*a;
b>>=1;
while(a>=1000)a/=10;
while(s>=1000)s/=10;
}
return s;
}
int main()
{
int T=read();
for(int gg=1;gg<=T;++gg)
{
n=read();k=read();
printf("Case %d: ",gg);
write(ppp(n,k));printf(" ");
write(fpow(n,k));puts("");
}
}
【LightOJ1282】Leading and Trailing(数论)的更多相关文章
- LightOJ1282 Leading and Trailing —— 指数转对数
题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing PDF (English) Statistics ...
- LightOJ-1282 Leading and Trailing 模算数 快速幂 对数的用法
题目链接:https://cn.vjudge.net/problem/LightOJ-1282 题意 给出两个正整数n(2 ≤ n < 231), k(1 ≤ k ≤ 1e7) 计算n^k的前三 ...
- LightOJ 1282 Leading and Trailing 数论
题目大意:求n^k的前三位数 和 后三位数. 题目思路:后三位数直接用快速幂取模就行了,前三位则有些小技巧: 对任意正数都有n=10^T(T可为小数),设T=x+y,则n=10^(x+y)=10^x* ...
- LightOJ1282 Leading and Trailing
题面 给定两个数n,k 求n^k的前三位和最后三位 Input Input starts with an integer T (≤ 1000), denoting the number of test ...
- Leading and Trailing (数论)
Leading and Trailing https://vjudge.net/contest/288520#problem/E You are given two integers: n and k ...
- Leading and Trailing(数论/n^k的前三位)题解
Leading and Trailing You are given two integers: n and k, your task is to find the most significant ...
- LightOJ 1282 Leading and Trailing (快数幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS Me ...
- UVA-11029 Leading and Trailing
Apart from the novice programmers, all others know that you can’t exactly represent numbers raised t ...
- E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。
/** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字, ...
随机推荐
- ThinkPHP的基本操作
一.生成入口文件 1.打开服务器,在本地环境测试时在地址栏输入localhost/项目文件名/index.php 可以在Application下面生成一个home模块,记得在这之前,要建立一个项目文 ...
- mac攻略(1) -- 简单配置php开发环境
[http://www.cnblogs.com/redirect/p/6112154.html] 最简单直接的方式还是使用 Mac 上自带的 Apache 和 PHP. 1.启动 Apache ...
- Linux中的 awk查找日志中的相关记录
假设要在 api.log.201707201830 文件中,(此文件的多个字段数据以不可见字符^A(键盘上按下Ctrl+V+A)分隔),要输出第70个字段: awk -F '^A' '{print $ ...
- 二分图最大匹配模板【匈牙利;Dinic最大流】
二分图最大匹配模板[匈牙利:Dinic最大流] 匈牙利算法 int n,m; vector<int> map[100010]; int match[100010];//保存匹配的互相点 b ...
- 装x玩法:插上你的专有U盘才能开机
玩法的效果是这样的: 1.插上你的专有U盘,按电脑开机按钮,电脑正常启动运行: 2.如果不插专有优U盘,按电脑开机按钮,进入桌面后1秒钟电脑自动关机,无法使用.也就是说,没有优U盘将无法使用你的电脑. ...
- Spring Boot 注解详解
一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...
- 正则表达式的方法:replace,match,test(replace参数可以是回调函数)
1.replace: 作用对象:字符串 功能:用于替换字符串中的某些字符 参数:(1)正则表达式 (2)要替换的字符串 或者 回调函数 var str="1 2 3 4 5 6 7 8 9& ...
- css渲染(二) 文本
一.文本样式 首行缩进 text-indent 首行缩进是将段落的第一行缩进,这是常用的文本格式化效果.一般地,中文写作时开头空两格.[注意]该属性可以为负值:应用于: 块级元素(包括block和i ...
- Qt msvc Modules
3D ActiveQt container ActiveQt server Bluetooth Concurrent Core Enginio Declarative Gui Help Locatio ...
- mysql 学习心得2
1tinyint small~ medium~ int big~ float double dec(M,D)定点数 取值范围由md确定 bit(M)位类型 bit(1) bit(64). 2zerof ...