The following code is taking 11.2 seconds on spoj cube platform whereas the time limit is 10 seconds.
A little optimization is needed. Please help.
#include<cstdio>
#include<vector>
using namespace std;
#define MAX 100000001
using namespace std;
int main()
{
vector<int> DIV(MAX);
vector<int> INVDIV(MAX);
int t;int count;
for (int i=1;i<=10000;i++) {count=i+1;DIV[i*i]+=i;for (int j=i*(i+1);j<MAX;j+=i) {DIV[j]+=i+count;count+=1;}}
for(int i=2;i<MAX;i++) if (DIV[i]<MAX) if (INVDIV[DIV[i]]==0) {INVDIV[DIV[i]]=i;}
INVDIV[1]=1;
int k;
scanf("%d",&t);
while(t--){
scanf("%d",&k);
if(INVDIV[k]!=0) printf("%d\n",INVDIV[k]);
else printf("-1\n");
}
return 0;
}