【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得前三位数字以及后三位数字, ...
随机推荐
- 【linux之正则表达式】
一.grep grep家族grep.egrep.fgrepGlobally search a Regular Expression and Print根据我们提供的模式进行查找,并且将文件中匹配的行显 ...
- stderr,stdout,a.txt缓冲区别
#include<stdlib.h>#include<stdio.h>#include<string.h>#include<error.h>#inclu ...
- Apollo学习
Apollo的配置 参考: Apollo 配置详细步骤(Windows环境) MQTT再学习 -- 搭建MQTT服务器及测试 分布式部署指南 Java客户端使用指南
- LNMP搭建04 -- 配置Nginx支持PHP
首先建立存放网页文件的目录,执行 mkdri /usr/local/server/www 然后进入到该目录中 cd /usr/local/server/www 然后创建一个测试文件: phpinfo ...
- php读取access数据库
<?php //读取mdb数据库 $conn = new com("ADODB.Connection"); $connstr = "DRIVER={Microsof ...
- 洛谷P4014 分配问题【最小/大费用流】题解+AC代码
洛谷P4014 分配问题[最小/大费用流]题解+AC代码 题目描述 有 n 件工作要分配给 n 个人做.第 i 个人做第 j 件工作产生的效益为c ij. 试设计一个将 n 件工作分配给 n 个人做的 ...
- shiro进行散列算法操作
shiro最闪亮的四大特征:认证,权限,加密,会话管理 为了提高应用系统的安全性,这里主要关注shiro提供的密码服务模块: 1.加密工具类的熟悉 首先来个结构图,看看shiro提供了哪些加密工具类: ...
- Java Integer类型比较
今天做了一道题目题目如下: Integer a=10; Integer b=10; System.out.print(a==b); Integer c=200; Integer d=200; Syst ...
- MySQL 参数- Innodb_File_Per_Table(独立表空间)
Innodb存储引擎可将所有数据存放于ibdata*的共享表空间,也可将每张表存放于独立的.ibd文件的独立表空间.共享表空间以及独立表空间都是针对数据的存储方式而言的. 共享表空间某一个数据库的所有 ...
- 在ASP.Net Core下,Autofac实现自动注入
之前使用以来注入的时候,都是在xml配置对应的接口和实现类,经常会出现忘了写配置,导致注入不生效,会报错,而且项目中使用的是SPA的模式,ajax报错也不容易看出问题,经常会去排查日志找问题. 于是在 ...