Prime Modified Z-Factorials

Aug 18 2020

ให้ฉันอธิบายทีละคำศัพท์ข้างต้น ...

เราจะโทรหา\$\text{Z-Factorial}(n)\$ของจำนวนเต็มบวก\$n\$, \$n!\$(กล่าวคือ\$n\$แฟกทอเรียล) โดยไม่มีศูนย์ต่อท้าย ดังนั้น\$\text{Z-Factorial}(30)\$คือ\$26525285981219105863630848\$เพราะ\$30!=265252859812191058636308480000000\$

เราจะเรียกModified Z-Factorialของ\$n\$, ที่\$\text{Z-Factorial}(n) \mod n\$.
ดังนั้นModified Z-Factorialจาก\$30\$คือ\$\text{Z-Factorial}(30) \mod 30\$ซึ่งก็คือ\$26525285981219105863630848 \mod 30 = 18\$

เรามีความสนใจในบรรดา\$n\$ซึ่งModified Z-Factorial of nเป็นหมายเลขเฉพาะ

ตัวอย่าง

หมายเลข\$545\$เป็นPMZเพราะ\$\text{Z-Factorial}(545) \mod 545 = 109\$ ซึ่งเป็นนายก

นี่คือรายการค่าแรกของ\$n\$ ที่ผลิต Prime Modified Z-Factorial (PMZ)

5,15,35,85,545,755,815,1135,1165,1355,1535,1585,1745,1895,1985,2005,2195,2495,2525,2545,2615,2705,2825,2855,3035,3085,3155,3205,3265,3545,3595,3695,3985,4135,4315,4385,4415,4685,4705,4985,5105,5465,5965,6085,6155,6185,6385,6415,6595...         

งาน

รายการด้านบนดำเนินต่อไปและงานของคุณคือค้นหา\$k\$th PMZ

อินพุต

จำนวนเต็มบวก\$k\$

เอาต์พุต

\$kth\$ PMZ

กรณีทดสอบ

ต่อไปนี้เป็นกรณีทดสอบ1 ดัชนี
โปรดระบุว่าคุณใช้ระบบการจัดทำดัชนีใดในคำตอบของคุณเพื่อหลีกเลี่ยงความสับสน
โซลูชันของคุณจำเป็นต้องทำงานภายในขอบเขตของขนาดจำนวนเต็มของภาษาของคุณเท่านั้น

input -> output     
 1        5     
 10       1355       
 21       2615     
 42       5465     
 55       7265      
 100      15935
 500      84815

นี่คือรหัสกอล์ฟดังนั้นคะแนนต่ำสุดในหน่วยไบต์จะชนะ

คำตอบ

3 SomoKRoceS Aug 18 2020 at 04:25

05AB1E , 16 ไบต์

[N!0ÜN%pi®>©¹Q#N

อินพุตคือ1-based k

เอาต์พุต k-th PMZ

คำอธิบาย:

[N!0ÜN%pi®>©¹Q#N
[                     Start infinite loop
 N!                   Factorial of the index
   0Ü                 Remove trailing zeros
     N%               Mod index
       p              Is prime?
        i             If it is:
         ®>©          Increment the value stored in register c (initially -1)
            ¹Q        Is the value equals the input?
              #N      If it does, push the index (which is the PMZ) and break

ลองออนไลน์!

3 JonathanAllan Aug 18 2020 at 01:36

เจลลี่ ,  13  11 ไบต์

!Dt0Ḍ%⁸Ẓµ#Ṫ

การอ่านโปรแกรมแบบเต็มจาก STDIN ซึ่งพิมพ์ผลลัพธ์ไปยัง STDOUT

ลองออนไลน์!

อย่างไร?

!Dt0Ḍ%⁸Ẓµ#Ṫ - Main Link: no arguments
         #  - set n=0 (implicit left arg) and increment getting the first
                (implicit input) values of n which are truthy under:
        µ   -   the monadic chain (f(n)):
!           -     factorial -> n!
 D          -     convert from integer to decimal digits
  t0        -     trim zeros
    Ḍ       -     convert from decimal digits to integer
      ⁸     -     chain's left argument, n
     %      -     modulo
       Ẓ    -     is prime?
          Ṫ - tail
            - implicit print
2 cairdcoinheringaahing Aug 18 2020 at 03:08

เพิ่ม ++ 58 ไบต์

D,f,@,Rb*BDBGbUdb*!!*BFJiA%P
x:?
Wx,`y,+1,`z,$f>y,`x,-z
Oy

ลองออนไลน์!

หมดเวลาสำหรับ\ $ k \ ge 30 \ $ใน TIO

มันทำงานอย่างไร

D,f,@,			; Define a function, f, taking 1 argument, n
			; Example:		STACK = [30]
	Rb*		; Factorial		STACK = [265252859812191058636308480000000]
	BD		; Convert to digits	STACK = [2 6 5 ... 0 0 0]
	BGbU		; Group adjacents	STACK = [[2] [6] [5] ... [8] [4] [8] [0 0 0 0 0 0 0]]
	db*!!		; If last is all 0s
	*BF		; 	remove it	STACK = [[2] [6] [5] ... [8] [4] [8]]
	Ji		; Join to make integer	STACK = [26525285981219105863630848]
	A%		; Mod n			STACK = [18]
	P		; Is prime?		STACK = [0]
			; Return top value	0

x:?			; Set x to the input

Wx,			; While x > 0
	`y,+1,		;	y = y + 1
	`z,$f>y,	;	z = f(y)
	`x,-z		;	x = x - z
			; We count up with y
			; If y is PMZ, set z to 1 else 0
			; Subtract z from x, to get x PMZs

Oy			; Output y
2 Shaggy Aug 18 2020 at 05:56

Japt , 13 ไบต์

0- ดัชนี ทำงานได้เฉพาะในทางปฏิบัติสำหรับการ0และ1เป็นครั้งเดียวที่เราจะไปกว่า21!เราเกิน MAX_SAFE_INTEGERJavaScript

ÈÊsÔsÔuX j}iU

ลองมัน

ÈÊsÔsÔuX j}iU     :Implicit input of integer U
È                 :Function taking an integer X as argument
 Ê                :  Factorial
  s               :  String representation
   Ô              :    Reverse
    sÔ            :  Repeat (There has to be a shorter way to remove the trailing 0s!)
      uX          :  Modulo X
         j        :  Is prime?
          }       :End function
           iU     :Pass all integers through that function, returning the Uth one that returns true
2 DominicvanEssen Aug 18 2020 at 16:57

R , 99 93 ไบต์

แก้ไข: -6 ไบต์ (และ -4 ไบต์จากรุ่นที่กำหนดเอง - แม่นยำ) ขอบคุณ Giuseppe

k=scan();while(k){F=F+1;z=gamma(F+1);while(!z%%5)z=z/10;x=z%%F;k=k-(x==2|all(x%%(2:x^.5)))};F

ลองออนไลน์!

ใช้วิธีการที่ตรงไปตรงมาตามขั้นตอนของคำอธิบาย น่าเสียดายที่ความแม่นยำของตัวเลขRเกินขีด จำกัดที่แฟกทอเรียล (21) ดังนั้นจึงล้มเหลวสำหรับ k> 2

รุ่นที่มีความแม่นยำตามอำเภอใจ (ซึ่งไม่ จำกัด เฉพาะ k ขนาดเล็ก แต่มีการแข่งขันกอล์ฟน้อยกว่า) คือ:
R + gmp, 115 ไบต์

2 Razetime Oct 23 2020 at 15:15

แกลบ 11 ไบต์

!foṗS%ȯ↔↔ΠN

ลองออนไลน์!

คำอธิบาย

!foṗS%ȯ↔↔ΠN
 f        N filter list of natural numbers by:
         Π  take factorial
       ↔↔   reverse twice, remove trailing zeros
     S%     mod itself
    ṗ       is prime?
!           get element at index n
1 Arnauld Aug 18 2020 at 01:21

JavaScript (Node.js) ,  89 ... 79  77 ไบต์

n=>(g=y=>y%10n?(p=k=>y%--k?p(k):~-k||--n?g(x*=++i):i)(y%=i):g(y/10n))(x=i=2n)

ลองออนไลน์!

1 ManishKundu Aug 18 2020 at 03:17

งูหลาม 3 , 145 140 138 129 ไบต์

def f(n,r=0):
 c=d=2
 while r<n:
  c+=1;d*=c
  while 1>d%10:d//=10
  i=d%c;r+=i==2or i and min(i%j for j in range(2,i))
 return c

ลองออนไลน์!

Python 2 , 126125ไบต์

def f(n,r=0):
 c=d=2
 while r<n:
	c+=1;d*=c
	while d%10<1:d/=10
	i=d%c
	r+=i==2or i and min(i%j for j in range(2,i))
 print c

ลองออนไลน์!


คำอธิบาย: ให้หารด้วย 10 ตราบเท่าที่แฟกทอเรียลปัจจุบันหารด้วย 10 ได้จากนั้นตรวจสอบจำนวนปัจจุบันของแฟกทอเรียลโมดูโลสำหรับความเป็นจริง

ขอบคุณcaird coinheringaahingสำหรับ -20 ไบต์และDominic van Essenสำหรับ -9 ไบต์!

1 AZTECCO Aug 18 2020 at 23:22

Haskell , 129111ไบต์

g n
 |n`mod`10>0=n
 |0<1=g$div n 10 f=(!!)[n|n<-[1..],let p=mod(g$product[1..n])n,[x|x<-[2..p],mod p x<1]==[p]]

ลองออนไลน์!

gลบ0s จากตัวเลข

fใช้kองค์ประกอบ th จากความเข้าใจรายการที่ไม่มีที่สิ้นสุดโดยที่:
[x|x<-[2..p],mod p x==0]==[p]คือprimeเงื่อนไข (เปรียบเทียบรายการตัวหารของpและรายการของเพียง p)

และpเป็นแบบโมดูโลของปัจจัยผ่านmod(g$foldr(*)1[1..n])ng

บันทึก 18 ขอบคุณผู้ใช้