Why this c++ code fails for larger input?

Revision en1, by Vedkribhu, 2020-05-23 12:41:13

Problem: link Code in c++ which produces different output for k=10^5. Same logic in python giving AC.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long p = 1e9+7;
 
int main(){
	ll k;cin>>k;
	ll i,j,dp[100005], par[2] = {1,0};
	for(i=1;i<k+1;i++){
		dp[i]+=(par[(i+1)%2])%p;
		par[i%2]+=(dp[i])%p;
	}
	cout<<dp[k]%p<<endl;
}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Vedkribhu 2020-05-23 12:41:13 583 Initial revision (published)