Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- int NrDiv(int n)
- {
- int a=2;
- for(int i=2;i<=sqrt(n);i++)
- {
- if(n%i==0 && i*i!=n) a+=2;
- else
- if(i*i==n)
- a++;
- //cout << i << " a: " << a << endl;
- }
- return a;
- }
- int NextNrDiv(int n)
- {
- int a=NrDiv(n),b=2,c=n+2;
- while(a)
- {
- for(int i=2;i<=sqrt(c);i++)
- if(c%i==0 && i*i!=c) b+=2;
- else
- if(i*i==c)
- b++;
- if(a==b)
- return c;
- b=2;
- c+=2;
- }
- }
- int PrevNrDiv(int n)
- {
- int a=NrDiv(n),b=2,c=n-2;
- while(a)
- {
- for(int i=2;i<=sqrt(c);i++)
- if(c%i==0 && i*i!=c) b+=2;
- else
- if(i*i==c)
- b++;
- if(a==b)
- return c;
- b=2;
- c-=2;
- if(c<=1)
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement