×

 0 1 #include using namespace std; int main(){ long long int n,k,ctr=0,*arr; scanf("%I64d %I64d",&n,&k); arr = new long long int[n]; for(long long int i=0;i

Two wrong things at the same time!

1.) scanf("%d%d", &n, &k); There should be two "%d", u have to take values of both n and k, and ryt now you are taking only n.

2.) for(int i=0; i<=n :- Let me tell you, starting from i=0 to i=n, there are n+1 numbers, however you have to take only n numbers, So, "i<n" only.

So you are getting wrong answer because, k is taking value from the first element of the "so-typed-array" by you. Make the necessary changes.

2.0k21432
accept rate: 20%

Thanks ! I made the necessary corrections, but it still gives me a "Wrong Answer" on CodeChef. I also ran this code on Orwell Dev-C++ 5.7.1 - and it seems to be running fine on the test cases I tried it out on. Any suggestions ?

(30 Sep '14, 23:53) 0★
1

Woah! Hey i took ur code and made a small change. Now i am printing the elements as soon as they are being stored. U see this.

# include <cstdio>

using namespace std;
int main(){
long long int n,k,ctr=0,*arr;
scanf("%I64d %I64d",&n,&k);
arr = new long long int[n];

for(long long int i=0;i<n;i++){
scanf("%I64d",&arr[i]);
printf("%I64d\n",arr[i]);
}

for(long long int j=0;j<n;j++){
if(arr[j]%k==0){
++ctr;
}
}

printf("%I64d",ctr);
delete[] arr;
return 0;
}


Just for testing.

(01 Oct '14, 12:21)
1

Now what happened is:- U chck it urself. Type

7 3 1 51 966369 7 9 999996 11

which is the sample case given in problem and check the result! :-D u will be shocked. Now let me tell you the reason. The problem lies with "%I64d". Chnage it to "%lld" which is the standard specifier for long long integers. Ur output will be fine then.

(01 Oct '14, 12:32)

That works ! Thanks a lot ! By the way, Can you explain why %lld works, but not %I64d ?

(01 Oct '14, 14:16) 0★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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,476
×1,919
×856
×112
×49
×40
×32
×24

question asked: 28 Sep '14, 20:28

question was seen: 1,863 times

last updated: 01 Oct '14, 14:16