Call an positive integer almost-square if it can be written as , where and are integers and . How many almost-square positive integers are less than or equal to 1000000 ? Your score will be equal to .
Solution
To get a good estimate for the number of almost-square integers, note that any number of the form , with , will be by definition almost-square. Let's assume that it's relatively unlikely that a number is almost-square in more than one way. Then the number of almostsquare numbers less than will be approximately which is about . So, will be a fairly good estimate for the number of almost-square numbers less than , making 160000 a reasonable guess. We can do better, though. For example, we summed all the way up to , but we are really overcounting here because when is close to will be less than only when , as opposed to . So we should really be taking the sum In the process of taking the sum, we saw that we had something between and , so we could also guess something between 166000 and 125000, which would give us about 145000, an even better answer. If we actually calculate , we see that it's about 0.14384, so 143840 would be the best guess if we were to use this strategy. In reality, we would want to round down a bit in both cases, since we are overcounting (because numbers could be square-free in multiple ways), so we should probably answer something like 140000. A final refinement to our calculation (and perhaps easier than the previous one), is to assume that the products that we consider are randomly distributed between 1 and , and to compute the expected number of distinct numbers we end up with. This is the same type of problem as number 31 on this contest, and we compute that if we randomly distribute numbers between 1 and then we expect to end up with distinct numbers. When , we get that this equals Giving us an answer of 134000, which is very close to the correct answer. The actual answer was found by computer, using the following C++ program: ``` #include <stdio.h> using namespace std; bool isAlmostSquare(int n){ for(int k=1;k*k<=n;k++) if(n%k==0 && 3*(n/k) <= 4*k) return true; return false; } int main(){ int c = 0; for(int n=1;n<=1000000;n++) if(isAlmostSquare(n)) c++; printf("%d\n",c); return 0; } ```