class PrimeNumbers: @staticmethod def check(self, a,b): k = a while k > 1: if a%k == 0 and b %k == 0: return False else: k -= 1 return True def pairwisePrimes(self, number): x = [1,2,3,5,7,11,13,17,23,29,31,37] count = 0 for i in range(1,number/3+2): for j in range(i+1, number/2): for k in range(j+1,number): if i + j + k == number and PrimeNumbers.check(self, i,j ) and PrimeNumbers.check(self, j,k) and self.check(self,i,k): count += 1 return count ''' Implement a class PrimeNumbers that contains a method pairwisePrimes. The method inputs an int (num) and returns the number of ways the number can be written as the sum of three distinct integers that are pairwise relatively prime; that is no pair of the three integers has a common factor greater than 1. Note: - num is greater than 0 and less than or equal to 40. - One of the three distinct integer can be 1; Numbers are Pairwise Relatively Prime if they share no factor GREATER than 1. Method Signature: public int pairwisePrimes( int ); Examples: For num=8: 8 can be written as 1+2+5 and 1+3+4 and the method should return 2. For num=18, the method should return 14 '''
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