結果

問題 No.550 夏休みの思い出(1)
ユーザー cielciel
提出日時 2017-07-30 04:40:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 35 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-04-19 13:18:49
合計ジャッジ時間 5,928 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
12,416 KB
testcase_01 AC 90 ms
13,440 KB
testcase_02 AC 87 ms
13,184 KB
testcase_03 AC 90 ms
13,184 KB
testcase_04 AC 90 ms
13,056 KB
testcase_05 AC 90 ms
13,184 KB
testcase_06 AC 88 ms
13,184 KB
testcase_07 AC 91 ms
13,056 KB
testcase_08 AC 89 ms
13,184 KB
testcase_09 AC 79 ms
12,416 KB
testcase_10 AC 81 ms
12,288 KB
testcase_11 AC 79 ms
12,288 KB
testcase_12 AC 79 ms
12,544 KB
testcase_13 AC 75 ms
12,160 KB
testcase_14 AC 79 ms
12,544 KB
testcase_15 AC 80 ms
12,544 KB
testcase_16 AC 74 ms
12,160 KB
testcase_17 AC 74 ms
12,416 KB
testcase_18 AC 76 ms
12,160 KB
testcase_19 AC 78 ms
12,160 KB
testcase_20 AC 77 ms
12,416 KB
testcase_21 AC 77 ms
12,160 KB
testcase_22 AC 79 ms
12,288 KB
testcase_23 AC 75 ms
12,160 KB
testcase_24 AC 78 ms
12,288 KB
testcase_25 AC 81 ms
12,800 KB
testcase_26 AC 76 ms
12,160 KB
testcase_27 AC 76 ms
12,288 KB
testcase_28 AC 76 ms
12,160 KB
testcase_29 AC 76 ms
12,544 KB
testcase_30 AC 76 ms
12,160 KB
testcase_31 AC 76 ms
12,288 KB
testcase_32 AC 75 ms
12,288 KB
testcase_33 AC 78 ms
12,288 KB
testcase_34 AC 79 ms
12,288 KB
testcase_35 AC 77 ms
12,160 KB
testcase_36 AC 76 ms
12,160 KB
testcase_37 AC 78 ms
12,416 KB
testcase_38 AC 77 ms
12,288 KB
testcase_39 AC 78 ms
12,416 KB
testcase_40 AC 77 ms
12,288 KB
testcase_41 AC 77 ms
12,288 KB
testcase_42 AC 77 ms
12,288 KB
testcase_43 AC 78 ms
12,544 KB
testcase_44 AC 75 ms
12,416 KB
testcase_45 AC 75 ms
12,416 KB
testcase_46 AC 76 ms
12,160 KB
testcase_47 AC 76 ms
12,288 KB
testcase_48 AC 75 ms
12,160 KB
testcase_49 AC 73 ms
12,160 KB
testcase_50 AC 74 ms
12,160 KB
testcase_51 AC 77 ms
12,160 KB
testcase_52 AC 77 ms
12,416 KB
testcase_53 AC 75 ms
12,288 KB
testcase_54 AC 75 ms
12,288 KB
testcase_55 AC 74 ms
12,160 KB
testcase_56 AC 76 ms
12,160 KB
testcase_57 AC 76 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
class Integer
	def pow_binary_mod(y,m)
		x = self
		z = 1
		while y!=0
			z=z*x%m if y&1!=0
			x=x*x%m
			y>>=1
		end
		z
	end
	def miller_rabin
		n=self.abs #todo#
		return true if n==2
		return false if n==1||n%2==0
		d=n-1
		s=0
		while d%2==0
			d/=2
			s+=1
		end
		a=1
		5.times{|_| #todo#
			a+=1
			a+=1 while a.gcd(n)!=1 #todo#
			r=a.pow_binary_mod(d,n)
			next if r==1||r==n-1
			if s.times.none?{|j|
				r=r.pow_binary_mod(2,n)
				r==n-1
			}
				return false
			end
		}
		return true
	end
	def rho3
		#get one divisor
		def rhonext(x,n,seed) (x*x+seed)%n end
		n=self
		#raise if n<2
		[1,3,5].each{|seed| #todo#
			x=y=1 #todo#
			q=i=1
			loop{
				if i==q
					y=x
					q*=2
				end
				x=rhonext(x,n,seed)
				d=(x-y).abs.gcd(n)
				if d>1
					break if d==n
					return d
				end
				i+=1
			}
		}
		nil
	end
	def rho2
		#get all divisors
		n=self
		#raise if n<2
		r=[]
		while n>1
			if n.miller_rabin
				return r+[n]
			else
				x=n.rho3
				if !x
					STDERR.puts 'suspicious: %d'%n
					return r+[n]
				end
				r+=x.rho2
				n/=x
			end
		end
		r
	end
	def rho
		n=self
		r=[]
		if n<0
			r<<-1
			n=-n
		end
		return r if n<2
		[2].each{|e| #todo#
			while n%e==0
				n/=e
				r<<e
			end
		}
		return r if n==1
		r+n.rho2
	end
end

A,B,C=gets.split.map &:to_i
K=C==0?B: C
h=Hash.new 0
[-1,*K.abs.rho].each{|e|h[e]+=1}
c=h.map{|n,p|(0..p).map{|i|n**i}}
puts [0,*c.shift.product(*c).map{|_|_.reduce(1,:*)}].select{|x|x**3+A*x**2+B*x+C==0}.sort*' '
0