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>usingnamespacestd;constunsignedlonglongMOD=1ULL<<31;constintBITSET_SIZE=MOD/64;// Number of 64-bit blocks (approx 33.5 million)unsignedlonglongmask[BITSET_SIZE]={0};boolinsert(unsignedx){unsignedidx=x>>6;// Divide by 64 to get block indexunsignedpos=x&63;// Modulo 64 to get bit positionif((mask[idx]&(1ULL<<pos))==0){mask[idx]|=(1ULL<<pos);returntrue;}returnfalse;}intmain(){ios::sync_with_stdio(false);cin.tie(nullptr);unsignedlonglongN,S,P,Q;cin>>N>>S>>P>>Q;unsignedlonglonga=S%MOD;unsignedlonglongdistinct=0;// Insert first elementif(insert(a))distinct++;for(unsignedlonglongi=1;i<N;i++){a=(a*P+Q)%MOD;if(insert(a))distinct++;}cout<<distinct<<"\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 →