java - Find No of divisor -
i have 1 programming question asking find count of numbers between (1 , x) divisible 2 , factor of 2 + 3 , factor of 3 + 5 , factor of 5.
i solved , algo below-
total count of nos between 1 , x= sum of ( no of factor of x '2 , factor of 2'=x/2 no of factor of x '3 , factor of 3'=x/3 no of factor of x '5 , factor of 5'=x/5) -common number
now problem here how common numbers included in above calculation. example have find count of no between 1 , 30 divisible above 3 , factor of them then
for 2 numbers ->2,4,6,....30 3 numbers ->3,6,9...30 5 numbers ->5,10,15...30
see here have counted 30 in each case have remove count how big x value please help
let's consider numbers 1 x set. set can divided subsets:
divisible 2, 3, 5 , none of them. sets intersect. approach good, needs changed. should count how many numbers count 2 , 3 @ same time, 2 , 5 etc. when you'll assure can fill diagram numbers, you're ready code.
for example, can instantly fill intersection of 3 sets floor of x/30
. go way (remember, it's floor each time!):
Comments
Post a Comment