Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package problem23;
- public class Problem23 {
- public static int sumOfDivisors(int number) {
- int sum = 0;
- int compare = number - 1;
- while (compare > 0) {
- if (number % compare == 0) {
- sum += compare;
- }
- compare--;
- }
- return sum;
- }
- public static void main(String[] args) {
- long beg = System.currentTimeMillis();
- boolean[] isAbundant = new boolean[28124];
- for (int i = 0; i <= 28123; i++) {
- if (i < sumOfDivisors(i)) {
- isAbundant[i] = true;
- }
- }
- boolean[] canBeWritten = new boolean[28124];
- for (int i = 1; i < isAbundant.length; i++) {
- if (isAbundant[i]) {
- for (int j = 1; j < isAbundant.length; j++) {
- if (isAbundant[j] && j + i < canBeWritten.length) {
- canBeWritten[i+j]=true;
- }
- }
- }
- }
- int resultat=0;
- for(int i = 1;i<canBeWritten.length;i++){
- if(canBeWritten[i]==false){
- resultat+=i;
- }
- }
- System.out.println(resultat);
- long end = System.currentTimeMillis();
- System.out.println(end-beg + " ms.");
- }
- }
Add Comment
Please, Sign In to add comment