Guest User

Untitled

a guest
Apr 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package problem23;
  2.  
  3. public class Problem23 {
  4.  
  5.     public static int sumOfDivisors(int number) {
  6.         int sum = 0;
  7.         int compare = number - 1;
  8.         while (compare > 0) {
  9.             if (number % compare == 0) {
  10.                 sum += compare;
  11.             }
  12.             compare--;
  13.         }
  14.  
  15.  
  16.         return sum;
  17.     }
  18.  
  19.     public static void main(String[] args) {
  20.         long beg = System.currentTimeMillis();
  21.         boolean[] isAbundant = new boolean[28124];
  22.         for (int i = 0; i <= 28123; i++) {
  23.             if (i < sumOfDivisors(i)) {
  24.                 isAbundant[i] = true;
  25.             }
  26.         }
  27.         boolean[] canBeWritten = new boolean[28124];
  28.         for (int i = 1; i < isAbundant.length; i++) {
  29.             if (isAbundant[i]) {
  30.                 for (int j = 1; j < isAbundant.length; j++) {
  31.                     if (isAbundant[j] && j + i < canBeWritten.length) {
  32.                         canBeWritten[i+j]=true;
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.         int resultat=0;
  38.         for(int i = 1;i<canBeWritten.length;i++){
  39.             if(canBeWritten[i]==false){
  40.                 resultat+=i;
  41.             }
  42.         }
  43.         System.out.println(resultat);
  44.         long end = System.currentTimeMillis();
  45.         System.out.println(end-beg + " ms.");
  46.     }
  47. }
Add Comment
Please, Sign In to add comment