We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int t;
int divisors=0;
long num = 1,i=2,ans[100000]={0};
int max = -1;
scanf("%d",&t);
int test_case[t];
for (int i=0; i<t; i++) {
scanf("%d",&test_case[i]);
if(max<test_case[i]) max = test_case[i];
}
while (divisors<max) {
num += i++;
int div = 1;
int m = sqrt(num);
if((long) pow((long) sqrt(num), 2)== num) div++;
else m = sqrt(num)+1;
for (long i = 2; i<m; i++)
if(num%i == 0) div += 2;
if(div>divisors) {
divisors = div;
ans[divisors] = num;
}
}
for (int i = 0; i<t; i++) {
int j = test_case[i];
while (ans[j] == 0) { j++; }
printf("%ld\n",ans[j]);
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #12: Highly divisible triangular number
You are viewing a single comment's thread. Return to all comments →
code in c:
int main() {
}