【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(数论)的更多相关文章

  1. LightOJ1282 Leading and Trailing —— 指数转对数

    题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing    PDF (English) Statistics ...

  2. LightOJ-1282 Leading and Trailing 模算数 快速幂 对数的用法

    题目链接:https://cn.vjudge.net/problem/LightOJ-1282 题意 给出两个正整数n(2 ≤ n < 231), k(1 ≤ k ≤ 1e7) 计算n^k的前三 ...

  3. LightOJ 1282 Leading and Trailing 数论

    题目大意:求n^k的前三位数 和 后三位数. 题目思路:后三位数直接用快速幂取模就行了,前三位则有些小技巧: 对任意正数都有n=10^T(T可为小数),设T=x+y,则n=10^(x+y)=10^x* ...

  4. LightOJ1282 Leading and Trailing

    题面 给定两个数n,k 求n^k的前三位和最后三位 Input Input starts with an integer T (≤ 1000), denoting the number of test ...

  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. LightOJ 1282 Leading and Trailing (快数幂 + 数学)

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

  8. UVA-11029 Leading and Trailing

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

  9. E - Leading and Trailing 求n^k得前三位数字以及后三位数字,保证一定至少存在六位。

    /** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字, ...

随机推荐

  1. 使用CentOS Linux Bridge搭建Vxlan环境

    一. 基础环境使用VmWare虚拟两台Linux机器.CentOS 7,Linux内核如下:4.5.3-1.el7.elrepo.x86_64如果内核版本太低,是不支持VxLan的.可以使用一下命令进 ...

  2. 原生js总结(干货)

    1.js基本数据类型 number string boolean underfined null 2.查找文档中的特定元素 document.getElementById("id" ...

  3. 自动化测试工具selenium的使用

    1.自动化测试的前提

  4. JMeter之Http协议接口性能测试

    一.不同角色眼中的接口 1.1,开发人员眼中的接口    1.2,测试人员眼中的接口 二.Http协议基本介绍 2.1,常见的接口协议 1.:2. :3. :4.:5.: 6. 2.2,Http协议栈 ...

  5. SQL替换语句 批量修改、增加、删除字段内容

    sql替换语句,用该命令可以整批替换某字段的内容,也可以批量在原字段内容上加上或去掉字符. 命令总解:update 表的名称 set 此表要替换的字段名=REPLACE(此表要替换的字段名, '原来内 ...

  6. java9 - 异常处理

    Java异常 1.异常初见 System.out.println(1/0); 运行上面语句之后打印出: Exception in thread "main" java.lang.A ...

  7. Flask下载文件

    前言 由于最近在做文件管理模块的功能,所以难免会遇到文件上传下载这块的功能.不过文件上传那块是调用的OSS api,所以接触的不多. 文件的下载: 1. 接口返回真实的文件 这种情况比较简单, fla ...

  8. DevExpress XtraGrid如何使单元格只读?

    -----------------------------从别人那里copy来的-------------------------------------------------- 1.   设置Gr ...

  9. hashtable的运用实例

    #include <hash_set> #include <iostream> using namespace std; int main() { hashtable<i ...

  10. 经典卷积神经网络(LeNet、AlexNet、VGG、GoogleNet、ResNet)的实现(MXNet版本)

    卷积神经网络(Convolutional Neural Network, CNN)是一种前馈神经网络,它的人工神经元可以响应一部分覆盖范围内的周围单元,对于大型图像处理有出色表现. 其中 文章 详解卷 ...