1 快速读入
2.1 C++的数字快速读入
inline int read()
{
char ch;
bool flag = false;
int a = 0;
while(true) {
ch = getchar();
if(ch >= '0' && ch <= '9' || ch == '-') {
break;
}
}
(ch == '-') ? (flag = true) : (a = a * 10 + ch - '0');
while(true) {
ch = getchar();
if(ch >= '0' && ch <= '9') {
a = a * 10 + ch - '0';
} else {
break;
}
}
if(flag) {
a = -a;
}
return a;
}
2.2 java的快速读入
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
AC solver = new AC();
solver.solve(in, out);
//只有在测试用例输出完全后才会输出
out.close();
}
}
class AC {
InputReader in;
PrintWriter out;
int prime[]=new int[1000];
int tot;
boolean check[]=new boolean[2020];
void init() { //现行筛素数的方法,时间复杂度为O(n)
Arrays.fill(check,false);
int i,j;
tot=0;
for(i=2;i<2000;i++) {
//out.println(i);
if(!check[i])prime[tot++]=i;
for(j=0;j<tot;j++) {
if(i*prime[j]>2000)break;
check[i*prime[j]]=true;
if(i%prime[j]==0)break;
}
}
//for(i=0;i<tot;i++)out.println(prime[i]);
}
public void work(){
int T;
T=in.nextInt();
while(T!=0){
T--;
BigInteger a,b=BigInteger.ONE;
int i=0;
a=in.nextBigInteger();
for(i=0;i<tot;i++)
{
b=b.multiply(BigInteger.valueOf(prime[i]));
if(b.compareTo(a)>0)break;
}
b=b.divide(BigInteger.valueOf(prime[i]));
out.println(b);
}
}
public void solve(InputReader in, PrintWriter out) {
this.in = in; this.out = out;
//ubuntu(乌班图操作系统) 下以ctrl + d终止 while(in.hasNext())
init();
work();
}
}
class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
if (!hasNext())
throw new RuntimeException();
return tokenizer.nextToken();
}
boolean hasNext() {
while (tokenizer == null || !tokenizer.hasMoreTokens())
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e) {
return false;
}
return true;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
}