Topic links
Find the number of circular bits that are odd number
This is hard for me to write, not violent at all.
Wikipedia link Wikipedia above is very good, the above algorithm implementation is good.
That's the top.
Java Program:
Packageproject61; Public classp64{voidrun () {intCount = 0; intm = 0; intD = 1; inta0 = 0; intA = 0; intPeriod = 0; for(intS = 2; s<10000; s++) {Period= 0; M= 0; D= 1; A0= (int) (Math.sqrt (S)); if(a0*a0 = = S)Continue; A=A0; Do{m= D*a-m; D= (s-m*m)/D; A= (a0+m)/D; Period++; } while(a!=2*a0); if(period%2==1) count++; } System.out.println (count); } Public Static voidMain (string[] args) {LongStart =System.currenttimemillis (); NewP64 (). run (); LongEnd =System.currenttimemillis (); LongTime =end-start; System.out.println ("Run Time:" + time/1000+ "s" +time%1000+ "MS"); }}
Python program
ImportTime as time start=time.time () Count=0 forSinchRange (2,10000): M=0 D= 1A0= Int (s**0.5) ifa0*a0 = = S:ContinuePreiod=0 A=A0 whilea!=2*a0:m= D*a-m D= (s-m*m)/D a= Int ((a0 + m)/d) Preiod+=1ifPreiod%2==1:count +=1End=time.time ()Print "time={0} secs,count={1}". Format ((End-start), count)
The top two programs are almost the same
Euler Project question 64th: Odd period square roots