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.
#include<cmath>#include<cstdio>#include<iostream>#include<algorithm>usingnamespacestd;typedefunsignedintll;classBitArray{ll*v,n,size;enum{wordbits=sizeof(ll)*8};intcounter=0;public:BitArray(ll_n):n(_n){size=(n+wordbits-1)/wordbits;v=newll[size];for(lli=0;i<size;++i)v[i]=0;}voidinsert(llitem){v[item/wordbits]|=1<<item%wordbits;++counter;}boolisMember(llitem)const{returnv[item/wordbits]&(1<<item%wordbits);}intcount(){returncounter;}};intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */llN,S,P,Q,count=0;cin>>N>>S>>P>>Q;llmodulo=1LL<<31;BitArraybitA(modulo);llprv=S&(modulo-1);bitA.insert(prv);for(count=1;count<N;++count){prv=(prv*P+Q)&(modulo-1);if(!bitA.isMember(prv))bitA.insert(prv);}cout<<bitA.count();return0;}
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 →
Here is my solution.