SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | ||
3 | public class problem23{ | |
4 | public static void Main(){ | |
5 | int size = 28123; | |
6 | int[] array = new int[size]; | |
7 | ||
8 | for(int i = 0; i<size; i++){ | |
9 | - | for(int i = 0; i<size-1; i++){ |
9 | + | |
10 | } | |
11 | /* | |
12 | int sum = 0; | |
13 | for(int i = 0; i<size; i++){ | |
14 | if(isAbundant(i)){ | |
15 | Console.WriteLine(i); | |
16 | sum++; | |
17 | ||
18 | } | |
19 | } | |
20 | Console.WriteLine(sum); | |
21 | */ | |
22 | for(int i= size-1 ; i>0 ; i--) { | |
23 | for(int j = 12 ; j<i ; j++ ){ | |
24 | int temp = i - j; | |
25 | if(isAbundant(j) && isAbundant(temp)){ | |
26 | array[i] = 0; | |
27 | Console.WriteLine(j +"\t"+ temp+"\t"+ i); | |
28 | break; | |
29 | } | |
30 | } | |
31 | } | |
32 | int total = 0; | |
33 | for(int i= size-1 ; i>0 ; i--){ | |
34 | if(array[i] == 1){ | |
35 | total += i; | |
36 | } | |
37 | } | |
38 | Console.WriteLine(total); | |
39 | } | |
40 | ||
41 | private static bool isAbundant(int n){ | |
42 | return allFactors(n) > n; | |
43 | } | |
44 | ||
45 | private static int allFactors(int n){ | |
46 | int total = 0; | |
47 | double limit = Math.Sqrt(n); | |
48 | for(int i=1;i<limit;i++){ | |
49 | if(n%i==0){ | |
50 | total += (i+n/i); | |
51 | } | |
52 | } | |
53 | return total-n; | |
54 | } | |
55 | ||
56 | ||
57 | ||
58 | } |