湘潭oj1203/邀請賽A稱號 數論+java瞼板

來源:互聯網
上載者:User

標籤:

乞討 n%1+n%2+n%3+n%4+.........n%n=,n<=10^12次要。

一味的找規律之初。沒有發現。後來,前輩執教後,人才平淡,所以,現在唯一明確的。


首先在地圖上:


對於該題,在求區間(根號n,n),因為n%i=n-i*x(這裡x是從1枚舉到根號n,每一個k 相應n/(x+1)~n/x區間內。因為是等差數列(還是遞減)。直接用公式求和)。

哎(根號n,n)區間是被切割來求得。分成根號n次。

import java.io.*;import java.util.Scanner;import java.math.BigInteger;public class Main{public static void main(String[] args) {int T;    Scanner in=new Scanner(System.in);    T=in.nextInt();    for(int ii=1;ii<=T;ii++)                    {          long n;                                              BigInteger sum=new BigInteger("0");           n=in.nextLong();           long lasta=2*n;        for(long i=1;i*i<n;i++)        {         sum=sum.add(BigInteger.valueOf(n%i));         if((i+1)>=lasta){break;}              //邊界推斷          long b=n/i;              long a=n/(i+1)+1;              BigInteger temp1=BigInteger.valueOf(n);         //將一個 long型資料轉為biginteger              temp1=temp1.multiply(BigInteger.valueOf((b-a+1)));                 BigInteger temp2=BigInteger.valueOf(b+a);              temp2=temp2.multiply(BigInteger.valueOf(i));    //*              temp2=temp2.multiply(BigInteger.valueOf(b-a+1));                 temp2=temp2.divide(BigInteger.valueOf(2));   //除以              temp1=temp1.subtract(temp2);                 // -            sum=sum.add(temp1);                             //+           lasta=a;         }         System.out.println("Case "+ii+": "+sum);         //Java的println自己主動帶換行。注意!    }}}


著作權聲明:本文部落格原創文章,部落格,未經同意,不得轉載。

湘潭oj1203/邀請賽A稱號 數論+java瞼板

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.