題目鏈接:點擊打開鏈接
題意:略
思路:被卡的心力交瘁。。不願多說,主要是記錄一下java的快速讀寫,防止下次被這樣的無良出題人卡。
cpp版:
#include#include #include using namespace std; struct Bignb{ long long a,b,c; }; 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--) { printf("Case #%d: ",++cas); long long tp; scanf("%I64d",&tp); if(tp>1e9) { long long tp1=tp%(mod1); long long tp2=tp/(mod1); Bignb ans; ans.a=8*tp2*tp2; ans.b=16*tp1*tp2-7*tp2; ans.c=8*tp1*tp1-7*tp1+1; ans.c+=(mod1)*(ans.b%mod1); ans.a+=(ans.b/mod1); if(ans.c<0) { ans.c+=mod2; ans.a--; } else { ans.a+=ans.c/mod2; ans.c=ans.c%mod2; } if(ans.a<=0) { printf("%I64d\n",ans.c); } else { int cnt=0; long long tp=1; for(cnt=11;cnt>0;cnt--) { tp*=10; if(tp>ans.c) { break; } } //printf("cnt%d\n",ans.c); printf("%I64d",ans.a); for(int i=0;i
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(); } }