/** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字,保证一定至少存在六位. 思路:后三位求法只要不断对1000取余就行了. 前三位求法: 对一个数x,他可以用科学计数法表示为10^r*a (r为次方,1<=a<10) 设:n^k = x = 10^r*a 两边取对数: k*log10(n) = log10(x) = r+log10(a); 令y =…
1282 - Leading and Trailing You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. Input Input starts with an integer T (≤ 1000), denoting the number of test cases. Each…
Leading and Trailing You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. Input Input starts with an integer T (≤ 1000), denoting the number of test cases. Each case st…
题目大意:求n^k的前三位数 和 后三位数. 题目思路:后三位数直接用快速幂取模就行了,前三位则有些小技巧: 对任意正数都有n=10^T(T可为小数),设T=x+y,则n=10^(x+y)=10^x*10^y,其中10^x为10的整倍数(x为整数确定数位长度),所以主要求出10^y的值. T=log10(n^k)=klog10(n),可以调用fmod函数求其小数部分即y值. #include<iostream> #include<algorithm> #include<cst…
题意: 求n的k次方的前三位 和 后三位 ...刚开始用 Java的大数写的...果然超时... 好吧  这题用快速幂取模求后三位  然后用一个技巧求前三位 ...orz... 任何一个数n均可以表示为10a, 其中 a 可以为小数 那么nk 可以表示为10ak  , 令ak == x + y  (其中x为整数 y为小数)  所以 ak - x == y fmod(x,1)可以返回x的小数部分 所以y = fmod(ak,1) /*由于x是整数,那么很明显他是用来指定位数的,因为10x肯定是一个…
今天试着读取一份UTF-8格式的txt文件,内容如下 12345 但是每次读取之后转为String类型,输出字符串长度总是为6,并且第一位打印在控制台后不占任何空间. 经过debug查看字节码后发现,在读取文件后的字节流中,前三位的字节分别是 -17,-69,-65 经过查看资料才发现,这是utf-8格式所带的特殊字节.凡是utf-8格式的文件文件,都会有这三个字节. 这种情况会导致对读取后的字符串进行截取时出现问题. 比如读取日期格式时,内容为2018-09-29 00:00:00,而我想要的…
题意:给定\(a\)和\(n\),输出\(a^n\)的前三位和后三位 后三位快速幂 \(log_{10}(a^n)=n*log_{10}(a)=n*log_{10}(x*y),y<10,x mod 10 = 0\) \(n*log_{10}(x*y)=p+q,q<1\),\(p\)作为整数只是倍数上的贡献,其中前三位就是\(pow(10,q)*100\) #include<bits/stdc++.h> #define rep(i,j,k) for(register int i=j;…
title: Java生成前三位是字母循环的字典 date: 2018-08-17 18:52:22 tags: Java --- 最近要破解一个秘密,还好这个密码是有线索的,已知密码的前三位是三个字母,后五位是12345,所以干脆用代码生成字典的全部的可能. import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; public class createDic { public stat…
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:https://codeforces.com/contest/1080. A.Petya and Origami 题意:Petya要发出n张邀请函,每张请函需要2张红纸,5张绿纸,8张蓝纸.现在商店里有一些不同颜色的笔记本,每本中有k张颜色相同的纸,求最少要买几本笔记本. 这题就是一道模拟题,算出每种…
这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你我以前的号是灰名),还是挺高兴的,而且t神这场比赛又成第一了. 比赛传送门:http://codeforces.com/contest/1075 A. The King's Race 题意:有一黑一白两个旗子,白的在(1, 1)上,黑的在(n, n)上.每次可以将旗子移动到周围一圈这八个位置,给你三…
BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : Register Public   Contest Status : Ended Current Server Time : 2014-08-31 21:12:12 Solved Pro.ID Title Ratio(Accepted / Submitted)   1001 Little Pony…
sum Accepts: 822 Submissions: 1744 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Description Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. outpu…
题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 216    Accepted Submission(s): 166 Problem De…
总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高度的模拟,如果遇到石头就去判断一下会不会小于0其他没有什么好说的了 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int…
[LightOJ1282]Leading and Trailing(数论) 题面 Vjudge 给定两个数n,k 求n^k的前三位和最后三位 题解 这题..真的就是搞笑的 第二问,直接输出快速幂\(mod \ 1000\)的值,要补前导零 第一问...就是搞笑的 依旧是快速幂 但是用double来算 每次中间值只要大于1000 直接除得小于1000就行了 不会就看代码把.. 这题就是搞笑的... #include<iostream> #include<cstdio> #includ…
Leading and Trailing https://vjudge.net/contest/288520#problem/E You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. Input Input starts with an integer T (≤ 1000), den…
题意:给你 n 和 k ,让你求 n^k 的前三位和后三位 思路:后三位很简单,直接快速幂就好,重点在于如何求前三位,注意前导0 资料:求n^k的前m位 博客连接地址 代码: #include <iostream> #include <cmath> #include <cstdio> #include <algorithm> #define ll long long using namespace std; ll qmod(ll a,ll b,ll mod)…
题意:求nk的前三位和后三位. 分析: 1.后三位快速幂取模,注意不足三位补前导零. 补前导零:假如nk为1234005,快速幂取模后,得到的数是5,因此输出要补前导零. 2.前三位: 令n=10a,则nk=10ak=10x+y,x为ak的整数部分,y为ak的小数部分. eg:n=19,k=4,则nk=130321, a=log10(n)=1.2787536009528289615363334757569 ak=5.1150144038113158461453339030277, 因此,x=5,…
http://lightoj.com/volume_showproblem.php?problem=1282 Leading and Trailing Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1282 Description You are given two integers: n and k, your task is t…
Apart from the novice programmers, all others know that you can’t exactly represent numbers raised to some high power. For example, the C function pow(125456, 455) can be represented in double datatype format, but you won’t get all the digits of the…
题目链接:https://vjudge.net/problem/LightOJ-1282 1282 - Leading and Trailing    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are given two integers: n and k, your task is to find the most significant three digits, and le…
You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. Input Input starts with an integer T (≤ 1000), denoting the number of test cases. Each case starts with a line cont…
题解:求一个数的次幂,然后输出前三位和后三位,后三位注意有前导0的情况. 后三位直接用快速幂取模求解. 前三位求得时候只需要稍微变形一下,可以把乘过的结果拆成用科学计数法,那么小数部分只有由前面决定,所以取前三位利用double来计算就可以了. #include <bits/stdc++.h> using namespace std; typedef long long ll; const int Mod = 1000; ll ppow(ll a, ll k) // 后三位 { ll ans…
LightOJ - 1282 Leading and Trailing 题解 纵有疾风起 题目大意 题意:给你一个数n,让你求这个数的k次方的前三位和最后三位. \(2<=n<2^{31}\),\(1<=k<10^{7}\) 并且\(n^{k}\)至少有6位数 解题思路 这个题目需要解决两个问题 输出\(n^{k}\)的前三位 输出\(n^{k}\)的后三位 输出后三位 这个比较好解决,使用快速幂和模运算就能解决,这里不再详细介绍,看代码就行了. 输出前三位 这个比较麻烦,因为\(…
http://lightoj.com/volume_showproblem.php?problem=1282 题目大意: 求n的k次方的前三位和后三位数然后输出 后三位是用快速幂做的,我刚开始还是不会快速幂,后来慢慢理解了. 前三位求得比较厉害 我们可以吧n^k = a.bc * 10.0^m; k*log10(n)  = log10(a.bc) + m; m为k * lg(n)的整数部分,lg(a.bc)为k * lg(n)的小数部分; x = log10(a.bc) = k*log10(n)…
求n^k的前三位数字和后三位数字. 范围: n (2 ≤ n < 231) and k (1 ≤ k ≤ 107). 前三位: 设 n^k = x ---> lg(n^k)=lg(x) ---> klg(n)=lg(x) ---> x=10^(klgn).   因为求前三位,klgn大于2的整数部分可以舍弃.bit=floor(klgn-2), x=10^(klgn-bit). 后三位:快速幂模1000即可. 代码: #include <iostream> #inclu…
题目: 求n的k次方,然后将答案用前三位和最后三位表示. Sample Input 2 123456 1 123456 2 Sample Output 123...456 152...936 分析: 题目中其实有提示,用double来表示n的k次方,double神奇的地方在于能转化为string类型的字符串.用到了sprintf这个函数.代码: #include <cstdio> #include <iostream> #include <cstring> using…
题面 给定两个数n,k 求n^k的前三位和最后三位 Input Input starts with an integer T (≤ 1000), denoting the number of test cases. Each case starts with a line containing two integers: n (2 ≤ n < 2^31) and k (1 ≤ k ≤ 10^7). Solution 后面一问是搞笑的 前面一问? 也是搞笑的,用double除成小于1的数算就好了…
Sample Input 5 123456 1 123456 2 2 31 2 32 29 8751919 Sample Output Case 1: 123 456 Case 2: 152 936 Case 3: 214 648 Case 4: 429 296 Case 5: 665 669 题意:求一个数n的k次方后的前三位与后三位.并且后三位要求控制格式. 思路:这道题后三位可以用快速幂求出来,前三位就要用到log了.先说一下怎么求n^k的前三位. 我先设10^p=n^k,同时取log10…
题意:求 n^k 的前三位和后三位. 析:后三位,很简单就是快速幂,然后取模1000,注意要补0不全的话,对于前三位,先取10的对数,然后整数部分就是10000....,不用要,只要小数部分就好,然后取前三位. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #inc…