How many times does a function produce output?

69 Views Asked by At

I have a function f(n) for which I wish to get a count of the number of times f(n) yields an integer for a given arbitrary number k. Specifically, if n has factors of 3,5, or 7, f(n) will generate a number which is the square of that factor or combination of factors that divide n, otherwise, f(n) is blank. For example, f(1)=""; f(2)=""; f(3)=9; f(4)=""; f(5)=25;... f(7)=49;... f(15)=225; ..f(21)=441; ... f(105)=11025. I want to find how many non-blanks are generated if k=105.

I have tried the sum INT(105/3)=35 + INT(105)/5)=21 + INT(105/7)=15 and I get 71 but the proper number is 57 obtained by actual count. In the cases of 3*5=15, 3*7=21, and 5*7=35 as divisors of 105, we have counted twice so we should subtract one fo each. In the case of 3*5*7=105 as a divisor, we have generated only one entry (11025) but we have counted three times. The problem is that, to get the count of 57 I desire, I need to account for 14 occurrences of counting the prime factors more than once. I keep coming up with 16 or 12. Can anyone suggest the proper way to count non-blanks?

1

There are 1 best solutions below

0
On BEST ANSWER

I got just what I needed from Ethan Bolker who provided a link to wiki's inclusion exclusion principal page. I am only answering to take it off the open question queue. Thanks again Ethan.