We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Leonardo's Prime Factors
Leonardo's Prime Factors
+ 0 comments Java Solution:
class Result {
public static int primeCount(long n) { // Write your code here if(n==1){ return 0; }else if(n<=5){ return 1; }else if(n >= Long.parseLong("614889782588491410")){ return 15; }else{ List<Integer> prime=new ArrayList<>(Arrays.asList( 2,3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,61, 67)); long l=1; long h=1; for(int i=0;i< prime.size()-1; i++){ l=h; h *=Long.parseLong(Integer.toString(prime.get(i)) ); if(n >= l && n < h){ return i; } } } return -1; }
}
+ 0 comments C# solution:
public static int primeCount(long n) { ulong productOfPrimes=1; ulong[] firstPrimes= {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; for (int i = 0 ; i <firstPrimes.Length; i++){ productOfPrimes*=firstPrimes[i]; if(productOfPrimes > (ulong)n) return i; if(productOfPrimes == (ulong)n) return i+1; } return 0; }
+ 0 comments def primeCount(n): # Write your code here x = 0 s = 1 for i in range(2, n+1): flag = True for j in range(2, int(math.sqrt(i))+1): if i % j == 0: flag = False break if flag: s *= i if s > n: break x += 1 return x
+ 0 comments Using C++
int primeCount(long n) { if (n == 1) return 0; vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; unsigned long long m = 1; int cnt = 0; for (int prime : primes){ m *= (unsigned long long)prime; if (m > n) break; if (m == n){ cnt++; break; } cnt++; } return cnt; }
+ 0 comments primes =[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] def primeCount(n): total = 1 count = 0 if n == 2: return 1 for x in primes: total *= x count +=1 if total > n: break if total == n: return count elif total > n: return count-1
Load more conversations
Sort 315 Discussions, By:
Please Login in order to post a comment