Begging n%1+n%2+n%3+n%4+.........n%n=,n<=10^12 secondary.
Blindly looking for the law of the beginning. Not found. Later, after the senior coach, talent insipid, so, now the only clear.
First on the map:
For this problem, in the interval (root n,n), because n%i=n-i*x (here X is from 1 to the square root n, each k corresponding n/(x+1) ~n/x interval. Because it is arithmetic progression (or descending). Sum directly with the formula).
Ah (root n,n) interval is to be cut to obtain. Divided into square root n times.
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;} Boundary inference long b=n/i; Long a=n/(i+1) +1; BigInteger temp1=biginteger.valueof (n); Convert a Long data to 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)); Dividing Temp1=temp1.subtract (TEMP2); -Sum=sum.add (TEMP1); + lasta=a; } System.out.println ("Case" +ii+ ":" +sum); The Java println itself takes the initiative to bring a newline. Attention! }}}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Xiangtan OJ1203/Invitational A title number theory +java Eyelid plate