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

×

INTEST: Getting rte

My code is :

main(void)
{ 
    unsigned long int n,div,out=0;
    long long num;
    int i;
    scanf("%lu%lu",&n,&div);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&num);
        if(num<div)
        continue;

        else
        if(num%div == 0)
        out++;
    }

    printf("%d",out);

}

I am not sure as to why this results in a Runtime Error.

Any help would be highly appreciated.

asked 24 Mar '12, 00:57

cool_techie's gravatar image

2★cool_techie
28971218
accept rate: 22%

edited 10 Jul '12, 12:30

admin's gravatar image

0★admin ♦♦
19.8k350498541


In C language you need to have a return 0 when exiting from main. http://www.codechef.com/wiki/faq#Why_do_I_get_an_NZEC

link

answered 24 Mar '12, 02:35

gultus's gravatar image

4★gultus ♦
1.5k11325
accept rate: 51%

Thanks, it worked this time. But the time of execution was 5.55sec while some other solutions worked in .48sec

So can you help me to optimize the solution... Thanks a lot.

(24 Mar '12, 17:49) cool_techie2★

your out is declared as an unsigned long, but you print it as an int. moreover, it seems, regarding the problem statement, that storing num in a long long is not really necessary. an unsigned long should be enough. please tell us if it solves your problem :)

link

answered 24 Mar '12, 01:55

cyberax's gravatar image

3★cyberax ♦
3.4k21955
accept rate: 20%

edited 24 Mar '12, 01:56

The problem persists, I corrected the points mentioned by you but still it shows Runtime Error.

(24 Mar '12, 02:16) cool_techie2★

Your code is optimized except for long long for num. People whose execution is lesser, they optimize the I/O. ie they use block reading and their processing so that less I/O is performed. Generally without I/O optimized code passes in codechef, I/O optimization only reduces the execution time.

link

answered 28 Mar '12, 10:59

manishmap2's gravatar image

2★manishmap2
413
accept rate: 33%

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:

×2,718
×55
×49

question asked: 24 Mar '12, 00:57

question was seen: 1,917 times

last updated: 10 Jul '12, 12:30