Deceptive numbers: Difference between revisions

add C
(added langur language example)
(add C)
Line 96:
3367
4141</pre>
 
=={{header|C}}==
<syntaxhighlight lang="c">#include <stdio.h>
 
unsigned modpow(unsigned b, unsigned e, unsigned m)
{
unsigned p = 1;
while (e) {
if (e & 1)
p = p * b % m;
b = b * b % m;
e >>= 1;
}
return p;
}
 
int is_deceptive(unsigned n)
{
unsigned x;
if (n & 1 && n % 3 && n % 5) {
for (x = 7; x * x <= n; x += 6) {
if (!(n % x && n % (x + 4)))
return modpow(10, n - 1, n * 9) == 1;
}
}
return 0;
}
 
int main(void)
{
unsigned c, i = 49;
for (c = 0; c != 18; ++i) {
if (is_deceptive(i)) {
printf(" %u", i);
++c;
}
}
return 0;
}</syntaxhighlight>
{{out}}
<pre> 91 259 451 481 703 1729 2821 2981 3367 4141 4187 5461 6533 6541 6601 7471 7777 8149</pre>
 
=={{header|C++}}==
559

edits