【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得前三位数字以及后三位数字, ...
随机推荐
- 多路复用select
多路复用I/O:一个执行体监视多个文件描述符对象的状态是否改变,一旦改变通知其他执行体来实现. 基本思想: 1. 先构造一张有关描述符的表,然后调用一个函数,当这些文件描述符中的一个或者多个已准备好进 ...
- c语言环境初始化&c语言和汇编混合编程
bootloader通常会分为两个阶段:第一阶段采用汇编语言来编写,主要是一些核心的初始化工作(内存,时钟的初始化),第二阶段使用C语言来编写,主要是它会完成一些板载硬件的初始化(串口,网口)然后其启 ...
- [Python Study Notes]WdSaveFormat 枚举
WdSaveFormat 枚举 指定要在保存文档时使用的格式. 版本信息 已添加版本: 名称 值 说明 wdFormatDocument 0 Microsoft Word 格式. wdFormatDO ...
- 讲解mybaits的标签语法
前言:mybatis作为一个持久层的java框架,高度封装了jdbc原始代码,它拥有比Hiberante更便捷.更直接的sql语法和sql灵活配置的特性,比如简单的一个自动映射对象就大大减少了我们的代 ...
- java thread 线程锁同步,锁,通信
12.线程同步 当多个线程访问同一个数据时,非常容易出现线程安全问题.这时候就需要用线程同步 Case:银行取钱问题,有以下步骤: A.用户输入账户.密码,系统判断是否登录成功 B.用户输入取款金额 ...
- [Codeforces]817F. MEX Queries 离散化+线段树维护
[Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You sho ...
- CEF小白人系列1-认识CEF
手头上有个项目需要做浏览器的相关功能,评估了几个嵌入式方案最后选定CEF作为开发基础. 在入坑新技术的时候第一选择是去官网学习,这是一个非常好的习惯. CEF官网(请科学上网) https://bit ...
- 0基础学python3心得体会 - python3学习笔记 - python3基础
基础预热 print()会依次打印每个字符串,遇到逗号","会输出一个空格,可以打印整数,或者计算 结果 Python提供了一个input(),,可以让用户输入字符串,并存放到一个 ...
- javascript selenium全套教程发布
为什么有这个系列 目前javascript生态非常丰富,越来越多的人开始用js去做前端的ui测试了.而selenium是web ui测试的标准解决方案,所以一套js的selenium教程是很有必要的. ...
- 洛谷P3381 - 【模板】最小费用最大流
原题链接 题意简述 模板题啦~ 题解 每次都以费用作为边权求一下最短路,然后沿着最短路增广. Code //[模板]最小费用最大流 #include <cstdio> #include & ...