AlexAvram

tema info 6.10

Oct 5th, 2023
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. void cuburi(int n)
  2. {
  3. while (n)
  4. cout<<n*n*n<<" ", --n;
  5. }
  6.  
  7.  
  8.  
  9.  
  10.  
  11. void impar_oglindit(int x, int y, int &rez)
  12. {
  13. int a=0, b=0, u, p=1;
  14. while (x)
  15. {
  16. u=x%10;
  17. if (u%2==1)
  18. a=a+u*p, p*=10;
  19. x/=10;
  20. }
  21. while (y)
  22. {
  23. u=y%10;
  24. if (u%2==1)
  25. b=b*10+u;
  26. y/=10;
  27. }
  28. if ((!a && !b) || a!=b)
  29. rez=0;
  30. else
  31. rez=1;
  32. }
  33.  
  34.  
  35.  
  36.  
  37. bool prim(int a)
  38. {//faceti-va functia asta cum o stiti voi, ca se prinde daca o scrieti asa
  39. if ((a%2==0 && a!=2) || a<2)
  40. return 0;
  41. int d;
  42. for (d=3; d*d<=a; d+=2)
  43. if (a%d==0)
  44. return 0;
  45. return 1;
  46. }
  47. void prime(int n, int &x, int &y)
  48. {
  49. if (n%2==0)
  50. --n;
  51. else
  52. n-=2;
  53. x=0, y=0;
  54. while ((!x || !y) && n>1)
  55. {
  56. if (prim(n))
  57. {
  58. if (!y)
  59. y=n;
  60. else
  61. x=n;
  62. }
  63. n-=2;
  64. }
  65. if (x==0)
  66. x=2;//
  67. //pentru n=4 sau 5 daca merg cu pas 2, mi-l gasesti numai pe 3 si dupa se inchide fara sa imi gaseasca si un x
  68. //asa ca daca mi se inchide fara sa imi gaseasca ambele numere, il fac pe ala mai mic 2 ca e evident ca x=2
  69.  
  70. }
Add Comment
Please, Sign In to add comment