【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得前三位数字以及后三位数字, ...
随机推荐
- ajax常用操作
load的方法的使用(现在已不常用) <!doctype html><html lang="en"><head> <meta charse ...
- 阿里云 virtual memory exhausted: 无法分配内存
在阿里云买了个云服务器,内存1G.编译php时出现下面的错误: virtual memory exhausted: Cannot allocate memory 问题原因:由于物理内存本身很小,且阿里 ...
- iOS UIFont 字体名字大全
Font Family: American TypewriterFont: AmericanTypewriterFont: AmericanTypewriter-Bold Font Family: A ...
- Selenium常用方法及函数、txt参数化
常用方法及函数: 1.表单的提交方法:submit解释:查找到表单(from)直接调用submit即可实例:driver.find_element_by_id("form1").s ...
- java2 - 语言基础
一.结构流程图制作工具 xmind 的使用 二.Java 基础数据类型 回答以下问题: java 基本数据类型有几种? 整数类型是哪几种? 浮点数类型是哪几种? 字符类型关键字? 布尔类型关键字? 为 ...
- MYSQL索引的类型和索引的方式
索引的类型: normal:表示普通索引 unique:表示唯一的,不允许重复的索引,如果该字段信息保证不会重复例如身份证号用作索引时,可设置为unique full textl: 表示 全文搜索的索 ...
- Ecshop中transport和jquery不兼容的解决方案
1.修改文件:/js/transport.js,在最底部增加代码 if (Object.prototype.toJSONString){ var oldToJSONString = Object.to ...
- Shell脚本查看linux系统性能瓶颈(转)
Shell脚本查看linux系统性能瓶颈(转自:http://blog.51cto.com/lizhenliang/1687612) [root@test ~]# cat show_sys_info. ...
- basler 相机拍照简单类综合Emgu.CV---得到图档
在网上找了半天都是下载要钱,自己试做了,经测试能ok,一起分享吧.给初学的人一点鼓励. using System;using System.Collections.Generic;using Syst ...
- java网络编程(6)——实现一个服务器把小写转大写
实现一个服务器,通过我们发送的文本数据,然后转回大写放回,实现一个服务端与客户端的交互,用over来作为结束标记,具体代码如下: 客户端: package com.seven.tcp; import ...