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.
Disclamer: a bit upset with the problem statement
this pseudocode tells us that the sequence is actually linear(arithmetical)
and (mathematecaly) unbounded from the top.
so there is no use of Q%(2<<30) except once
so the sequence is a = p*a+q
there is no chance to repeate the value except overflow
but we do not know what data type we should use for the sequence and it is machine specific.
as the result: the solution
intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */unsignedintN,S,P,Q;cin>>N>>S>>P>>Q;Q%=(2<<30);unsignedinta0,a;a0=S%(2<<30);for(unsignedinti=0;i<N-1;i++){a=a0*P+Q;if(a0==a){N=i;break;}a0=a;}
cout<<N;
}
debuged on test case 8
worked for my local PC for unsigned long but for HackerRank envirement only for unsigned int
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bit Array
You are viewing a single comment's thread. Return to all comments →
Disclamer: a bit upset with the problem statement this pseudocode tells us that the sequence is actually linear(arithmetical) and (mathematecaly) unbounded from the top. so there is no use of Q%(2<<30) except once so the sequence is a = p*a+q there is no chance to repeate the value except overflow but we do not know what data type we should use for the sequence and it is machine specific. as the result: the solution
} debuged on test case 8 worked for my local PC for unsigned long but for HackerRank envirement only for unsigned int