SHARE
    TWEET
    AlexAvram

    #462 DivPrimMax

    Aug 29th, 2023
    66
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    text 1.05 KB | None | 0 0
    1. #include <iostream>
    2. using namespace std;
    3. bool ciur[1000001];
    4. int nrprim[78900];
    5. void eratostene()
    6. {
    7. int i, j, k=0;
    8. ciur[0]=ciur[1]=1;
    9. for (i=2; i<=1e3; ++i)
    10. if(ciur[i]==0)
    11. {
    12. for (j=i*i; j<=1e6; j+=i)
    13. ciur[j]=1;
    14. }
    15. for (i=1; i<=1e6; ++i)
    16. if (!ciur[i])
    17. nrprim[++k]=i;
    18. }
    19. int nrdivprim(int a)
    20. {
    21. int f, k=0, res=0; bool p;
    22. while (a>1)
    23. {
    24. f=nrprim[++k], p=0;
    25. if (f==0)
    26. break;
    27. while (a%f==0)
    28. a/=f, p=1;
    29. if (p)
    30. ++res;
    31. if (f*f>a)
    32. f=a;
    33. }
    34. return res;
    35. }
    36. int main()
    37. {
    38. eratostene();
    39. int a, b, x;
    40. int nrdivprimmax=-1, nr;
    41. cin>>a>>b;
    42. nrdivprimmax=nrdivprim(a), nr=a;
    43. while (a!=b)
    44. {
    45. x=nrdivprim(b);
    46. if (x>nrdivprimmax)
    47. nrdivprimmax=x, nr=b;
    48. else if (x==nrdivprimmax && b>nr)
    49. nr=b;
    50. a=b;
    51. cin>>b;
    52. }
    53. cout<<nr<<" "<<nrdivprimmax;
    54. return 0;
    55. }
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /