Hints: Mad Counting , It’s really a mad counting problem. To solved this problem, you have to think in a different way while you are counting. Since we have to count the minimum possible populations, It’s only possible when we…
Hints: Generate primes upto 10^7 and go through primes within an iterative approach and check: N- primes[i] is prime or not? Code:
Explanation: Let’s an arrray A[4]={1, 4, 3, 5}. According to given function, SUM: = (1-4)+(1-3)+(1-5)+(4-3)+(4-5)+(3-5) = 1-4+1-3+1-5+4-3+4-5+3-5 = 1+1+1+4+4+3-4-3-3-5-5-5 = (1×3)+(4×2)+(3×1)-(4×1)-(3×2)-(5×3) = ? Isn’t easy to get SUM from the array? Here is the code to get SUM: So, for…
Joshephus Problem is a very interesting mathematical problem. To solve this problem you have to think bottom to top approach. Since at the end there must be one alive, before then there was two alive. Result can be found through…
This problem can be solved using Binary Search. But I’ve found a one line solution using Basic Geometry. You can try to solve using using Binary Search. To learn Binary Search you can go through this way: Binary Search Explanation:…