Special divisors: Difference between revisions

Content added Content deleted
(Added PL/M)
(Add C++)
Line 162: Line 162:
{{output}}
{{output}}
<lang applescript>{|count|:72, finds:{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}}</lang>
<lang applescript>{|count|:72, finds:{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}}</lang>

=={{header|C++}}==
<lang cpp>#include <iostream>
#include <iomanip>
#include <vector>

using uint = unsigned int;

std::vector<uint> divisors(uint n) {
std::vector<uint> divs;
for (uint d=1; d<=n/2; d++) {
if (n % d == 0) divs.push_back(d);
}
return divs;
}

uint reverse(uint n) {
uint r;
for (r = 0; n; n /= 10) r = (r*10) + (n%10);
return r;
}

bool special(uint n) {
for (uint d : divisors(n))
if (reverse(n) % reverse(d) != 0) return false;
return true;
}

int main() {
for (uint n=1, c=0; n < 200; n++) {
if (special(n)) {
std::cout << std::setw(4) << n;
if (++c == 10) {
c = 0;
std::cout << std::endl;
}
}
}
std::cout << std::endl;
return 0;
}</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</pre>


=={{header|Delphi}}==
=={{header|Delphi}}==