#use one function for check isprime and findfactor def func(num,code): count = 0 i = 1 factor = [] while(i <= num): if((num % i) == 0): if( (code=="findfactor") and (func(i,"isprime")) ): factor = factor + [i] elif( code=="isprime" ): count +=1 i +=1 if( (count==2) and (code=="isprime") ): return True elif( code=="isprime" ): return False elif( code=="findfactor" ): return factor j = 1 index = {} while(j<1000001): #run the function factors = func(j,"findfactor") #calculate the product product = 1 i = 0 while(i < len(factors)): product = product*factors[i] i+=1 #check and count how many time every number appeared if(product in index): index[product] += 1 else: index[product] = 1 j+=1 #find largest number j = 0 maxtimes = 0 mode = 0 while(j<1000001): if((j in index) and (index[j] > maxtimes)): maxtimes = index[j] mode = j j+=1 print(str(mode)+"appeared"+str(index[mode])+"times")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question