File tree 1 file changed +21
-39
lines changed
1 file changed +21
-39
lines changed Original file line number Diff line number Diff line change 8
8
#define N 4
9
9
#define M 1000000
10
10
11
+ static int distinct_factor_count (unsigned n );
12
+
11
13
/* this program may take sevaral seconds */
12
14
int main (void )
13
15
{
14
- unsigned i ;
15
- for (i = 2 ; i < M ; i ++ ) {
16
- unsigned factors [N ][N ];
17
- unsigned j ;
18
-
19
- for (j = 0 ; j < N ; j ++ ) {
20
- unsigned c , k , l ;
16
+ unsigned i , j = 0 ;
17
+ for (i = 2 ; i < M && j < N ; i ++ ) {
18
+ for (j = 0 ; j < N && distinct_factor_count (i + j ) == 4 ; j ++ )
19
+ ;
20
+ }
21
+ printf ("%u\n" , i - 1 );
21
22
22
- for (c = 0 ; c < N ; c ++ ) {
23
- factors [j ][c ] = 1 ;
24
- }
23
+ return 0 ;
24
+ }
25
25
26
- /* factorize */
27
- k = i + j ;
28
- l = 2 ;
29
- c = 0 ;
30
- while (k != 1 && c < N ) {
31
- while (k % l == 0 ) {
32
- k /= l ;
33
- factors [j ][c ] *= l ;
34
- }
35
- l ++ ;
36
- if (factors [j ][c ] != 1 ) {
37
- c ++ ;
38
- }
39
- }
40
- if (c != N ) {
41
- /* too few factors */
42
- goto NEXT ;
43
- }
44
- if (k != 1 ) {
45
- /* too many factors */
46
- goto NEXT ;
26
+ int distinct_factor_count (unsigned n )
27
+ {
28
+ unsigned count = 0 ;
29
+ unsigned i ;
30
+ for (i = 2 ; i <= n ; i ++ ) {
31
+ if (n % i == 0 ) {
32
+ count ++ ;
33
+ n /= i ;
34
+ while (n % i == 0 ) {
35
+ n /= i ;
47
36
}
48
37
}
49
-
50
- /* this i is the answer! */
51
- printf ("%u\n" , i );
52
- break ;
53
- NEXT :
54
- ;
55
38
}
56
-
57
- return 0 ;
39
+ return count ;
58
40
}
59
41
You can’t perform that action at this time.
0 commit comments