A prime such that its decimal period's length is shared with no other prime is called a unique prime (as defined by Yates in 1980).
3, 11, 37, and 101 are unique primes, since they are the only primes with periods one ( 1/3=.3333), two (1/11=.090909... ), three and four respectively.
List the first 15 unique primes, explaining how you obtained them.
Copying a list from OEIS does not qualify as a solution, getting information from any source is encouraged.
The program lists the unique primes in the order of the length of period, rather than by magnitude of the number. It factors a number consisting of n 9's into primes and tests the cycle lengths of their reciprocals. Any that match the sought length are counted, and if the count is exactly one, that prime is listed for that cycle length.
10 point 80
20 open "uniqprim.txt" for output as #2
30 for Lngth=1 to 30
40 Nines=10*Nines+9
50 N=Nines:Lct=0:Goodfct=0:Fct=0
60 while N>1
65 Pfct=Fct
70 Fct=prmdiv(N)
80 if Fct=0 then
90 :if fnPrime(N) then
100 :Fct=N
110 if Fct>0 then
120 :N=N\Fct
130 :Tst$=str(1/Fct)
140 :Ix=instr(Tst$,".")
150 :Tst$=mid(Tst$,Ix+1,*)
160 :for Trlen=1 to Lngth
162 :Hit=1
163 :Maxoffset=(Lngth+7)*Trlen
164 :if Maxoffset>300 then Maxoffset=300:endif
167 :for Offset=0 to Maxoffset step Trlen
170 :if mid(Tst$,Offset+1,Trlen)<>mid(Tst$,Trlen+Offset+1,Trlen) then
175 :Hit=0
190 :endif
191 :next Offset
192 :if Hit=1 and Fct<>Pfct then
195 :cancel for:Goodfct=Fct:goto 220
196 :endif
200 :next Trlen
220 :if Trlen=Lngth then inc Lct:endif
230 :else
240 :N=0
250 wend
260 if N>0 then
270 :if Lct=1 then
280 :print Lngth,Goodfct
281 :print #2,Lngth,Goodfct
290 :endif
300 :else
310 :print Lngth,"too big"
311 :print #2,Lngth,"too big"
320
330 next Lngth
340
350
999 close #2
9998 end
9999 '
10000 fnOddfact(N)
10010 local K=0,P
10030 while N@2=0
10040 N=N\2
10050 K=K+1
10060 wend
10070 P=pack(N,K)
10080 return(P)
10090 '
10100 fnPrime(N)
10110 local I,X,J,Y,Q,K,T,Ans
10120 if N@2=0 then Ans=0:goto *EndPrime
10125 O=fnOddfact(N-1)
10130 Q=member(O,1)
10140 K=member(O,2)
10150 I=0
10160 repeat
10170 repeat
10180 X=fnLrand(N)
10190 until X>1
10200 J=0
10210 Y=modpow(X,Q,N)
10220 loop
10230 if or{and{J=0,Y=1},Y=N-1} then goto *ProbPrime
10240 if and{J>0,Y=1} then goto *NotPrime
10250 J=J+1
10260 if J=K then goto *NotPrime
10270 Y=(Y*Y)@N
10280 endloop
10290 *ProbPrime
10300 I=I+1
10310 until I>50
10320 Ans=1
10330 goto *EndPrime
10340 *NotPrime
10350 Ans=0
10360 *EndPrime
10370 return(Ans)
10380 '
10400 fnLrand(N)
10410 local R
10415 N=int(N)
10420 R=(int(rnd*10^(alen(N)+2)))@N
10430 return(R)
10440 '
10500 fnNxprime(X)
10510 if X@2=0 then X=X+1
10520 while fnPrime(X)=0
10530 X=X+2
10540 wend
10550 return(X)
10560 '
Only 11 were successfully found, for cycle lengths 1, 2, 3, 4, 9, 10, 12, 14, 19, 23 and 24. For cycle length 17 and lengths above 25, the program cannot say if the given length has such a prime, as at some point when factoring the number 999...9, a composite number was found where its smallest prime factor was too large for the UBASIC prmdiv() function.
length prime
1 3
2 11
3 37
4 101
9 333667
10 9091
12 9901
14 909091
17 too big
19 1111111111111111111
23 11111111111111111111111
24 99990001
26 too big
27 too big
28 too big
The length column corresponds to A007498 in the OEIS, and the prime column corresponds to A007615. I'm assuming that what was asked for was the first 15 items from A040017, which is ordered by the size of the prime rather than the length of the cycle.
|
Posted by Charlie
on 2017-11-24 14:22:49 |