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<iostream>#include<vector>usingnamespacestd;boolseenIT(unsignedlonglongsCurrent,vector<unsignedlonglong>&seen){size_tblk=sCurrent>>6;unsignedlonglongslot=1ULL<<(sCurrent&63);if(seen[blk]&slot)returntrue;seen[blk]|=slot;returnfalse;}intmain(){unsignedlonglongn,s,p,q;cin>>n>>s>>p>>q;constunsignedlonglongRANGE=1U<<31;//this many different #ssize_tblocks=(RANGE+63)/64;vector<unsignedlonglong>seen(blocks,0);//All start as 0, unseenseenIT(s,seen);boolearlyOut=false;for(inti=1;i<n;i++){s=(s*p+q)%RANGE;if(seenIT(s,seen)){earlyOut=true;cout<<i;break;}}if(!earlyOut)cout<<n;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 →
Working one. No more sprawling sets.