I wanted to store all the divisors of all the numbers from 1 to 10^6. But this seems too slow. This is the preprocess() function of my code:
for(int i=1; i<=1000000; i++)
{
for(int j=1; j<=i/2; j++)
{
if(i%j==0)
divi[i][j] = true;
}
}
I used map container like this:
map <int, bool> divi[1000010];
Then I tried to find the common divisors of two given numbers.
preprocess();
int T, A, B;
cin >> T;
while(T--)
{
cin >> A >> B;
int common = 0;
for(it = divi[A].begin(); it!=divi[A].end(); it++)
{
if(divi[B][it->first]==true)
common++;
}
cout << common << endl;
How should i approach now to make it faster enough?