题目链接:点击打开链接
题意:略
思路:被卡的心力交瘁。。不愿多说,主要是记录一下java的快速读写,防止下次被这样的无良出题人卡。
cpp版:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Bignb{
long long high,low;
void print(int& cas)
{
if(high<=0)
{
printf("Case #%d: %I64d
",++cas,low);
}
else {
printf("Case #%d: %I64d%012I64d
",++cas,high,low);
}
}
};
const long long mod1=1e6;
const long long mod2=1e12;
int main()
{
int T,cas=0;
// freopen("data.in","r",stdin);
scanf("%d",&T);
while (T--)
{
long long tp;
scanf("%I64d",&tp);
if(tp<1e9){
printf("Case #%d: %I64d
",++cas,tp*(8*tp-7)+1);
}
else {
long long tp1=tp%(mod1),tp2=tp/(mod1),temp=16*tp1*tp2-7*tp2;
Bignb ans;
ans.high=8*tp2*tp2;
ans.low=8*tp1*tp1-7*tp1+1;
ans.low+=(mod1)*(temp%mod1);
ans.high+=(temp/mod1);
if(ans.low<0){
ans.low+=mod2;
ans.high--;
}
else {
ans.high+=ans.low/mod2;
ans.low=ans.low%mod2;
}
ans.print(cas);
}
}
return 0;
}
java版:
import java.util.*;
import java.io.*;
import java.math.*;
public class test {
public static void main(String[] args) throws IOException{
BigInteger zero=BigInteger.valueOf(0);
BigInteger data1,data2;
int T;
Scanner cin = new Scanner(new BufferedInputStream(System.in));
PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));
T=cin.nextInt();
for(int cas=1;cas<=T;cas++){
data1=zero;
data2=zero;
data1=cin.nextBigInteger();
data2=data1.multiply(data1);
data2=data2.multiply(BigInteger.valueOf(8)).subtract(data1.multiply(BigInteger.valueOf(7))).add(BigInteger.ONE);
cout.printf("Case #%d: ",cas);
cout.println(data2);
// System.out.println("Case #"+cas+": "+data2);
}
cin.close();// cout.flush();
cout.close();
}
}