hdu 5047 Sawtooth 組合數學 高精度,hdusawtooth

來源:互聯網
上載者:User

hdu 5047 Sawtooth 組合數學 高精度,hdusawtooth

題目連結:點擊開啟連結

題意:略

思路:被卡的心力交瘁。。不願多說,主要是記錄一下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\n",++cas,low);        }        else {            printf("Case #%d: %I64d%012I64d\n",++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\n",++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();      }               }





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.