Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int NrDiv(int x) /// Calculez numarul nrd de divizori ai lui x
- {
- int nrd=1,k=x,p=0;
- while(!(k&1))
- ++p,k>>=1;
- nrd*=p+1;
- for(int d=3;d*d<=k;d+=2)
- {
- p=0;
- while(k%d==0)
- ++p,k/=d;
- nrd*=p+1;
- }
- if(k>1)
- nrd*=2;
- return nrd;
- }
- void Initializare(char S[],int Max) /// Initializarea multimii S
- {
- for(int i=1;i<=Max;++i)
- S[i/8]=S[i/8]&(255^(1<<(i%8)));
- }
- void Adaugare(char S[],int x)
- {
- S[x/8]=S[x/8]|(1<<(x%8));
- }
- void Afisez(char S[],int Max)
- {
- ofstream g("masterpiece001.out");
- for(int i=1;i<=Max;++i) /// Parcurg multimea S (vectorul de frecventa)
- if(S[i/8]&(1<<(i%8))) /// si daca bitul e 1
- g<<i<<' '; /// afisez i
- g.close();
- }
- int main()
- {
- int n,x,MAX=0,nrmaxdiv=0;
- char S[60010]={},F[60010]={}; /// F retine o singura data fiecare numar
- ifstream f("masterpiece001.in");
- f>>n;
- int nrd;
- for(int i=1;i<=n;++i)
- {
- f>>x;
- if(x>MAX) /// Retin valoarea maxima x citita
- MAX=x;
- if(!(F[x/8]&(1<<(x%8)))) /// Daca bitul corespunzator lui x este 0
- {
- F[x/8]=F[x/8]|(1<<(x%8)); /// Pun bitul corespunzator al lui x pe 1
- nrd=NrDiv(x);
- if(nrd>nrmaxdiv)
- {
- nrmaxdiv=nrd;
- Initializare(S,MAX);
- Adaugare(S,x);
- }
- else
- if(nrd==nrmaxdiv)
- Adaugare(S,x);
- }
- }
- f.close();
- Afisez(S,MAX);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement