Find the number of positive integers n such that 1 ≤ n ≤ 1000 and n is divisible by [n1/3]
(In reply to
Solution by Larry)
Actually there are 172. In some instances, n^(1/3) -- or n**(1/3) -- will return a value that's slightly below the true integral cube root. That's the purpose of the crr being rounded in my program to check its cube to see if it matches n. I noticed that some perfect cubes were not being counted, and that was the reason, and I put in the check for perfect cubes.
Also see the analytic solution at the bottom.
ct=0;
for n=1:1000
cr=floor(n^(1/3));
crr=round(n^(1/3));
if mod(n,cr) == 0 | crr^3==n
if crr^3==n
cr=crr;
end
ct=ct+1;
fprintf('%5d %5d %3d %3d ',ct,n,cr,n/cr)
if crr^3==n
fprintf('%s',"*")
end
fprintf('\n')
end
end
finds there are 172:
count n box quotient
1 1 1 1 *
2 2 1 2
3 3 1 3
4 4 1 4
5 5 1 5
6 6 1 6
7 7 1 7
8 8 2 4 *
9 10 2 5
10 12 2 6
11 14 2 7
12 16 2 8
13 18 2 9
14 20 2 10
15 22 2 11
16 24 2 12
17 26 2 13
18 27 3 9 *
19 30 3 10
20 33 3 11
21 36 3 12
22 39 3 13
23 42 3 14
24 45 3 15
25 48 3 16
26 51 3 17
27 54 3 18
28 57 3 19
29 60 3 20
30 63 3 21
31 64 4 16 *
32 68 4 17
33 72 4 18
34 76 4 19
35 80 4 20
36 84 4 21
37 88 4 22
38 92 4 23
39 96 4 24
40 100 4 25
41 104 4 26
42 108 4 27
43 112 4 28
44 116 4 29
45 120 4 30
46 124 4 31
47 125 5 25 *
48 130 5 26
49 135 5 27
50 140 5 28
51 145 5 29
52 150 5 30
53 155 5 31
54 160 5 32
55 165 5 33
56 170 5 34
57 175 5 35
58 180 5 36
59 185 5 37
60 190 5 38
61 195 5 39
62 200 5 40
63 205 5 41
64 210 5 42
65 215 5 43
66 216 6 36 *
67 222 6 37
68 228 6 38
69 234 6 39
70 240 6 40
71 246 6 41
72 252 6 42
73 258 6 43
74 264 6 44
75 270 6 45
76 276 6 46
77 282 6 47
78 288 6 48
79 294 6 49
80 300 6 50
81 306 6 51
82 312 6 52
83 318 6 53
84 324 6 54
85 330 6 55
86 336 6 56
87 342 6 57
88 343 7 49 *
89 350 7 50
90 357 7 51
91 364 7 52
92 371 7 53
93 378 7 54
94 385 7 55
95 392 7 56
96 399 7 57
97 406 7 58
98 413 7 59
99 420 7 60
100 427 7 61
101 434 7 62
102 441 7 63
103 448 7 64
104 455 7 65
105 462 7 66
106 469 7 67
107 476 7 68
108 483 7 69
109 490 7 70
110 497 7 71
111 504 7 72
112 511 7 73
113 512 8 64 *
114 520 8 65
115 528 8 66
116 536 8 67
117 544 8 68
118 552 8 69
119 560 8 70
120 568 8 71
121 576 8 72
122 584 8 73
123 592 8 74
124 600 8 75
125 608 8 76
126 616 8 77
127 624 8 78
128 632 8 79
129 640 8 80
130 648 8 81
131 656 8 82
132 664 8 83
133 672 8 84
134 680 8 85
135 688 8 86
136 696 8 87
137 704 8 88
138 712 8 89
139 720 8 90
140 728 8 91
141 729 9 81 *
142 738 9 82
143 747 9 83
144 756 9 84
145 765 9 85
146 774 9 86
147 783 9 87
148 792 9 88
149 801 9 89
150 810 9 90
151 819 9 91
152 828 9 92
153 837 9 93
154 846 9 94
155 855 9 95
156 864 9 96
157 873 9 97
158 882 9 98
159 891 9 99
160 900 9 100
161 909 9 101
162 918 9 102
163 927 9 103
164 936 9 104
165 945 9 105
166 954 9 106
167 963 9 107
168 972 9 108
169 981 9 109
170 990 9 110
171 999 9 111
172 1000 10 100 *
The perfect cubes are marked with an asterisk and are the ones that make the programming tricky, as n^(1/3) may sometimes come below the actual cube root by a tiny amount due to rounding errors. That's the reason for the crr variable (cube root rounded); if that is cubed and the result is n, the condition is satisfied.
Of course the analytical way has no such trickiness:
Numbers below 8 that are divisible by 1: 7
Numbers 8 thru 26 that are divisible by 2: 10
Numbers 27 thru 63 divisible by 3: 13
Numbers 64 thru 124 divisible by 4: 16
Numbers 125 thru 215 divisible by 5: 19
Numbers 216 thru 342 divisible by 6: 22
Numbers 343 thru 511 divisible by 7: 25
Numbers 512 thru 728 divisible by 8: 28
Numbers 729 thru 999 divisible by 9: 31
Number 1000 divisible by 10: 1
They add to 172. Well, there was one trickiness: remembering to include 1000.
|
Posted by Charlie
on 2020-12-14 12:04:51 |