TanveerAhsan wrote:You can't run such a loop. It will take more than a minute (probably).
Generate all the numbers whose prime factors are 2, 3, 5, 7 and insert them in a sorted list like we do in insertion sort. For example, 1 is a humble number. Now multiply it with 2, 3, 5 and 7 and the new list will be 1 2 3 5 7. Next take the 2nd humble number i.e. 2 and multiply it with 2, 3, 5, and 7 and the new list will be 1 2 3 4 5 6 7 10 14. Now take 3 and repeat the process. Repeat the same as required.
Yes... I used this method, and got accepted. There's a another way to do it:
int pos = 0;
int i, j, k, l
for (i = 0; i < limit; i++) {
for (j = 0; j < limit; j++) {
for (l = 0; l < limit; l++) {
for (m = 0; m < limit; m++) {
array[pos] = 2 ^ i * 3 ^ j * 5 ^ k * 7 ^ l; // 2 elevated to i, ...
pos++;
}
}
}
}
qsort(array, ...);
you can do it too. I don't tested if it gets and TLE
