You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// This is a typical Binary Search Problem Here I did Binary Search and Optimized my lcm function a lot.
2
-
// Here Number of Ugly numbers for any number is
3
+
// Here Number of Ugly numbers for any number is
3
4
// that number/a + that number/b + that number/c + that number/lcm(a,b,c) - that number/lcm(a,b) - that number/lcm(b,c) - that number/(a,c) and howzz that??
4
-
//See Lets suppose that number is 17 for which you are checking values and a = 2 , b=3 and c= 4 now figure out
5
-
//all the possible values for a = 2,4,6,8,10,12,14,16
6
-
//b = 3,6,9,12,15
7
-
//c = 4,8,12,16
8
-
//Now if we add them all we can see 4,6,8,16 are coming twice and 12 is coming thrice so we do lcm(2,3) = 6
9
-
//then we are basically multiple occurance of numbers divisible by 6 simlarly for lcm(2,4) & lcm(3,4)
10
-
//but any number which is divisble by all three of them we have deleted it 3 times we need at least so we are adding numbers which are divisble by lcm(2,3,4) which is 12 here So if suppose we are countering more numbers than n then h = mid-1 we need to move backward else we need to forward.
5
+
// See Lets suppose that number is 17 for which you are checking values and a = 2 , b=3 and c= 4 now figure out
6
+
// all the possible values for a = 2,4,6,8,10,12,14,16
7
+
// b = 3,6,9,12,15
8
+
// c = 4,8,12,16
9
+
// Now if we add them all we can see 4,6,8,16 are coming twice and 12 is coming thrice so we do lcm(2,3) = 6
10
+
// then we are basically multiple occurance of numbers divisible by 6 simlarly for lcm(2,4) & lcm(3,4)
11
+
// but any number which is divisble by all three of them we have deleted it 3 times we need at least so we are adding numbers which are divisble by lcm(2,3,4) which is 12 here So if suppose we are countering more numbers than n then h = mid-1 we need to move backward else we need to forward.
0 commit comments