Cristian_Prisecariu

Untitled

Apr 26th, 2020
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. //o functie pentru a verifica daca un nr este prim...
  7. bool prim(unsigned long long int n)
  8. {
  9. unsigned long long int d;
  10. if(n==2)
  11. return true;
  12. if(n<2 || n%2==0)
  13. return false;
  14. for(d=3; d*d<=n; d+=2)
  15. if(n%d==0)
  16. return false;
  17. return true;
  18. }
  19. // calculez nr de biti si verific daca nr de biti este prim
  20. bool nrDeBiti(unsigned long long int n)
  21. {
  22. unsigned long long int k=0;
  23. while(n)
  24. {
  25. ++k;
  26. n/=2;
  27. }
  28. if(prim(k))
  29. return true;
  30. return false;
  31. }
  32.  
  33. //citesc intervalul [a,b]...
  34. int main()
  35. {
  36. unsigned long long int a,b,c=0,i;
  37. cin>>a>>b;
  38. for(i=a; i<=b; ++i)
  39. {
  40. if(nrDeBiti(i))
  41. ++c;
  42. }
  43. cout<<c;
  44. return 0;
  45. }
  46. #1479 pretios de pe pbinfo
  47. rezultat 40pct...?
RAW Paste Data