Jump to content

Special divisors: Difference between revisions

Added Algol 68
(Added XPL0 example.)
(Added Algol 68)
Line 4:
Numbers n such that reverse(d) divides reverse(n) for all divisors d of n, where '''n < 200'''
<br><br>
 
=={{header|ALGOL 68}}==
<lang algol68>BEGIN # find numbers where reverse(d) divides reverse(n) for all divisors d #
# of n #
# returns n with the digits reversed #
OP REVERSE = ( INT n )INT:
BEGIN
INT reverse := 0;
INT v := ABS n;
WHILE v > 0 DO
reverse *:= 10 +:= v MOD 10;
v OVERAB 10
OD;
reverse * SIGN n
END # REVERSE # ;
# find the numbers up to 200 #
INT rd count := 0;
FOR n TO 199 DO
INT reverse n = REVERSE n;
BOOL reverse divisor := TRUE;
FOR d FROM 2 TO n OVER 2 WHILE reverse divisor DO
IF n MOD d = 0 THEN
# have a divisor of n #
reverse divisor := reverse n MOD REVERSE d = 0
FI
OD;
IF reverse divisor THEN
# all the divisors of n reversed divide n reversed #
print( ( " ", whole( n, -3 ) ) );
IF ( rd count +:= 1 ) MOD 10 = 0 THEN print( ( newline ) ) FI
FI
OD;
print( ( newline, "Found ", whole( rd count, 0 ), " ""special divisors"" below 200", newline ) )
END</lang>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 11
13 17 19 22 23 26 27 29 31 33
37 39 41 43 44 46 47 53 55 59
61 62 66 67 69 71 73 77 79 82
83 86 88 89 93 97 99 101 103 107
109 113 121 127 131 137 139 143 149 151
157 163 167 169 173 179 181 187 191 193
197 199
Found 72 "special divisors" below 200
</pre>
 
=={{header|Delphi}}==
3,044

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.