fork(3) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. int start = 1;
  10. int end = 65536;
  11.  
  12. int[] sieve = getDivisorCount(start, end);
  13. long sum = 0;
  14. for(int i=0;i<sieve.length;i++){
  15. sum += sieve[i];
  16. }
  17. System.out.println("divisor count: " + sum);
  18. }
  19.  
  20. public static int[] getDivisorCount(int a, int b){
  21. int[] sieve = new int[b - a + 1];
  22. double max = Math.ceil(Math.sqrt(b));
  23. for(int i = 1; i <= max; i++){
  24. int j = (a / i) * i;
  25. if(j < a)
  26. j += i;
  27. for( ; j <= b; j += i){
  28. double root = Math.sqrt(j);
  29. if(i < root){
  30. sieve[j - a] += 2;
  31. }else if(i == root){
  32. sieve[j - a]++;
  33. }
  34. }
  35. }
  36. return sieve;
  37. }
  38. }
Success #stdin #stdout 0.09s 380224KB
stdin
Standard input is empty
stdout
divisor count: 736974