You are not logged in. Please login at www.codechef.com to post your questions!

×

can someone optimise this code

int main()

{

long n,k;

scanf("%ld\n",&n);

long a[n];

for(long i= 0;i<n;i++)

scanf("%ld\n",&a[i]);

for(long i=0;i<n;i++)

{

k=0;

for(long j=3;j<a[i];j++)

if(j%3==0 || j%5==0)

k=k+j;

if(k>0)

printf("%ld\n",k);

else

printf("%ld\n",k);

}

return 0;

}

asked 24 Nov '18, 07:55

kasuthubh_0310's gravatar image

0★kasuthubh_0310
11
accept rate: 0%

edited 24 Nov '18, 07:58


Is it for https://www.hackerrank.com/contests/projecteuler/challenges/euler001 ?

The code has to be corrected first since it does not read input properly. You need to remove \n from the scanf calls.

Secondly, there are a lot of references on the net how to solve problem #1 of Project Euler. See for example https://www.mathblog.dk/project-euler-problem-1/

link

answered 25 Nov '18, 00:06

oleg_b's gravatar image

7★oleg_b
3195
accept rate: 16%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×205
×144

question asked: 24 Nov '18, 07:55

question was seen: 140 times

last updated: 25 Nov '18, 00:06