Hi!
I tried everything that came to my mind but I always get Time Limit Exceeded. I was wondering if I could use Eratostenes sieve here but I think that it is useless because I'm looking for divisors not prime numbers.
Here is my code (working but too slow):
#include <cstdio>
int dzielniki(int a) {
int tab[50000];
int x, wynik, j;
wynik=0;
x=0;
if (a==1) return 0;
for(int i=a/2;i>=1;i--)
if (a%i==0) {
tab[x]=i;
wynik+=tab[x];
x++;
}
return wynik;
}
int main()
{
int t;
int tab1[210000];
scanf("%d", &t);
for (int i=0;i<t;i++)
scanf("%d", &tab1[i]);
for (int k=0;k<t;k++)
printf("%d\n", dzielniki(tab1[k]));
return 0;
}
Please help me make my program faster.