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.
Can someone help? 2 of my test cases don't pass due to a time error.
include
int main ()
{
int t;
int sum = 0;
scanf ("%d", &t);
for (int j = 0; j < t; j++)
{
int n;
scanf ("%d", &n);
for (int i = 0; i < n; i++)
{
if (i % 3 == 0 || i % 5 == 0)
sum = sum + i;
}
printf("%d",sum);
sum=0;
}
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 #1: Multiples of 3 and 5
You are viewing a single comment's thread. Return to all comments →
Can someone help? 2 of my test cases don't pass due to a time error.
include
int main () { int t; int sum = 0; scanf ("%d", &t); for (int j = 0; j < t; j++) { int n; scanf ("%d", &n); for (int i = 0; i < n; i++) { if (i % 3 == 0 || i % 5 == 0) sum = sum + i; } printf("%d",sum); sum=0; }
return 0; }