Curzon numbers: Difference between revisions
m
syntax highlighting fixup automation
m (Python example) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 33:
=={{header|Arturo}}==
<
zero? (inc base^n) % inc base*n
Line 63:
print ["\n1000th Curzon with base" withBase "=" oneThousandth withBase]
print ""
]</
{{out}}
Line 114:
=={{header|C++}}==
{{libheader|GMP}}
<
#include <iostream>
#include <vector>
Line 147:
}
return 0;
}</
{{out}}
Line 195:
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
<
prettyprint ranges sequences ;
Line 209:
curzon 10 group simple-table. ;
2 10 2 <range> [ curzon. nl ] each</
{{out}}
<pre>
Line 250:
=={{header|FreeBASIC}}==
===Normal basic===
<
Function pow_mod(b As ULongInt, power As ULongInt, modulus As ULongInt) As ULongInt
Line 291:
Next
Sleep</
1 2 5 6 9 14 18 21 26 29
30 33 41 50 53 54 65 69 74 78
Line 342:
===GMP version===
{{libheader|GMP}}
<
Dim As Longint t = Len(__mpz_struct)
Line 371:
Loop
Next k
Sleep</
=={{header|Go}}==
{{trans|Wren}}
<
import (
Line 421:
fmt.Println()
}
}</
{{out}}
Line 479:
'''Preliminaries'''
<
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
Line 489:
n;
def printRows($m): _nwise($m) | map(lpad(5)) | join("");</
'''The task'''
<
($k | power($n) + 1) % ($k * $n + 1) == 0;
Line 509:
"";
printcurzons(2; 10; 1000)</
{{out}}
<pre>
Line 540:
=={{header|Julia}}==
<
function printcurzons(klow, khigh)
Line 556:
printcurzons(2, 10)
</
<pre>
Curzon numbers with k = 2:
Line 584:
It isn't clear why the task description says "generalized Curzon numbers only exist for even base integers." If k >= 3 is an odd base, then, besides the trivial solution n = 1, it can be checked that n = k^(k-1) is a Curzon number according to the given definition. It seems from the output below that Curzon numbers with an odd base are much scarcer than those with an even base.
<
program CurzonNumbers;
uses SysUtils;
Line 653:
ListCurzonNumbers(11);
end.
</syntaxhighlight>
{{out}}
<pre>
Line 714:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
CurzonNumberQ[b_Integer][n_Integer]:=PowerMod[b,n,b n+1]==b n
val=Select[Range[100000],CurzonNumberQ[2]];
Line 734:
val=Select[Range[100000],CurzonNumberQ[10]];
Take[val,50]
val[[1000]]</
{{out}}
<pre>{1, 2, 5, 6, 9, 14, 18, 21, 26, 29, 30, 33, 41, 50, 53, 54, 65, 69, 74, 78, 81, 86, 89, 90, 98, 105, 113, 114, 125, 134, 138, 141, 146, 153, 158, 165, 173, 174, 186, 189, 194, 198, 209, 210, 221, 230, 233, 245, 249, 254}
Line 757:
=={{header|Perl}}==
<
use warnings;
use Math::AnyNum 'ipow';
Line 776:
(sprintf "@{['%5d' x $upto]}", @C[0..$upto-1]) =~ s/(.{125})/$1\n/gr;
print "Thousandth: $C[-1]\n\n";
}</
{{out}}
<pre>First 50 Curzon numbers using a base of 2:
Line 804:
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 828:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</
{{out}}
<pre>
Line 858:
=={{header|Python}}==
<
return (k**n + 1) % (k * n + 1) == 0
Line 871:
print(f'{c: 5,}', end='\n' if (i + 1) % 25 == 0 else '')
print(f' Thousandth Curzon with k = {k}: {curzons[999]}.\n')
</
<pre>
Curzon numbers with k = 2:
Line 901:
=={{header|Quackery}}==
<
space 4 of swap join
-5 split nip echo$ ] is rjust ( n --> )
Line 933:
say " ... "
-1 peek echo cr cr ]
</syntaxhighlight>
{{out}}
Line 979:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
for <2 4 6 8 10> {
Line 986:
$curzon[^50].batch(25)».fmt("%4s").join("\n") ~
"\nOne thousandth: " ~ $curzon[999]
}</
{{out}}
<pre>First 50 Curzon numbers using a base of 2:
Line 1,014:
=={{header|Rust}}==
<
// rug = "1.15.0"
Line 1,045:
println!("1000th Curzon number with base {k}: {n}\n");
}
}</
{{out}}
Line 1,092:
=={{header|Sidef}}==
<
powmod(k, n, k*n + 1).is_congruent(-1, k*n + 1) && (n > 0)
}
Line 1,100:
say 50.by {|n| is_curzon(n, k) }.join(' ')
say ("1000th term: ", 1000.th {|n| is_curzon(n,k) })
}</
{{out}}
Line 1,127:
=={{header|Vlang}}==
{{trans|go}}
<
fn main() {
Line 1,167:
println('')
}
}</
{{out}}
Line 1,221:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<
import "./gmp" for Mpz
Line 1,252:
}
System.print()
}</
{{out}}
|