Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <cmath>
  2.  
  3.  
  4. int NrDiv(int n)
  5. {
  6. int a=2;
  7. for(int i=2;i<=sqrt(n);i++)
  8. {
  9. if(n%i==0 && i*i!=n) a+=2;
  10. else
  11. if(i*i==n)
  12. a++;
  13. //cout << i << " a: " << a << endl;
  14. }
  15. return a;
  16. }
  17. int NextNrDiv(int n)
  18. {
  19. int a=NrDiv(n),b=2,c=n+2;
  20. while(a)
  21. {
  22. for(int i=2;i<=sqrt(c);i++)
  23. if(c%i==0 && i*i!=c) b+=2;
  24. else
  25. if(i*i==c)
  26. b++;
  27. if(a==b)
  28. return c;
  29. b=2;
  30. c+=2;
  31. }
  32. }
  33. int PrevNrDiv(int n)
  34. {
  35. int a=NrDiv(n),b=2,c=n-2;
  36. while(a)
  37. {
  38. for(int i=2;i<=sqrt(c);i++)
  39. if(c%i==0 && i*i!=c) b+=2;
  40. else
  41. if(i*i==c)
  42. b++;
  43. if(a==b)
  44. return c;
  45. b=2;
  46. c-=2;
  47. if(c<=1)
  48. return -1;
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement