nicuvlad76

Untitled

Nov 26th, 2022
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #define N 205
  3. using namespace std;
  4. /**
  5.  Algoritmi elementari sub forma de functii
  6. */
  7.  
  8. void Divizori(int n) ///afisare O(n/2)
  9. {
  10.     cout<<1<<" ";
  11.     for(int d=2;d<=n/2;d++)
  12.         if(n%d==0) cout<<d<<" ";
  13.     if(n!=1) cout<<n;
  14.    /// cout<<"\n";
  15. }
  16.  
  17. int SumaDiv(int n) ///O(sqrt(n))
  18. {
  19.     int s=0,d;
  20.     for(d=1;d*d<n;d++)
  21.         if(n%d==0)s+=d+n/d;
  22.     if(d*d==n) s+=d;
  23.     return s;
  24. }
  25.  
  26. int Cmmdc(int a, int b)///
  27. {
  28.     int r;
  29.     while(b!=0)
  30.     {
  31.         r=a%b;
  32.         a=b;
  33.         b=r;
  34.     }
  35.     return a;
  36. }
  37.  
  38. void Cmmdc(int a, int b, int &sol)///supraincarcare functie si parametru de iesire
  39. {
  40.     int r;
  41.     while(b!=0)
  42.     {
  43.         r=a%b;
  44.         a=b;
  45.         b=r;
  46.     }
  47.     sol=a;
  48. }
  49.  
  50. bool Prim(int x) ///O(sqrt(n)/2)
  51. {
  52.     if(x<2) return 0;
  53.     if(x==2) return 1;
  54.     if(x%2==0) return 0;
  55.     for(int d=3;d*d<=x;d+=2)
  56.         if(x%d==0)return 0;
  57.     return 1;
  58. }
  59.  
  60. void DescFactori(int n)
  61. {
  62.     int d=2,p;
  63.     while(n!=1)
  64.     {
  65.         p=0;
  66.         while(n%d==0) p++,n/=d;
  67.         if(p) cout<<d<<" "<<p<<"\n";
  68.         if(d*d<n)d++;
  69.         else d=n;
  70.     }
  71.    /// cout<<"\n";
  72. }
  73.  
  74. int IndicatorEuler(int n)
  75. {
  76.     double phi=n;
  77.     int p, d=2;
  78.     while(n!=1)
  79.     {
  80.         p=0;
  81.         while(n%d==0) p++,n/=d;
  82.         if(p) phi*=(d-1.0)/d;
  83.         if(d*d<n)d++;
  84.         else d=n;
  85.     }
  86.     return int(phi);
  87. }
  88.  
  89. int Fibo(int n) ///al n termen
  90. {
  91.     int f1=1,f2=1,f;
  92.     if(n==1 || n==2) return f1;
  93.     for(int i=3;i<=n;i++)
  94.     {
  95.         f=f1+f2;
  96.         f1=f2;
  97.         f2=f;
  98.     }
  99.     return f;
  100. }
  101. ///B10-Bq 10(10)= 1010(2)
  102. long long B10BQ(int n10, int q)
  103. {
  104.     long long nq=0, p=1;
  105.     while(n10!=0)
  106.     {
  107.         nq=nq+p*(n10%q);
  108.         p*=10;
  109.         n10/=q;
  110.     }
  111.     return nq;
  112. }
  113. ///bq-b10
  114. int BQB10(long long nq, int q)
  115. {
  116.     int n10=0, p=1;
  117.     while(nq!=0)
  118.     {
  119.         n10=n10+p*(nq%10);
  120.         p*=q;
  121.         nq/=10;
  122.     }
  123.     return n10;
  124.  
  125. }
  126.  
  127. ///formula lui Legendre
  128. /**
  129.   cate valori de p se gasesc in   n!=1*2*3*4*5*...*n
  130.  
  131.   np=[n/p]+[n/p^2]+[n/p^3]+...
  132.  
  133.         1 2 3 4 5 6 7 8 9 10
  134.   2  :    1   2   1   3    1 = 8
  135.   5  :          1          1 = 2
  136.   3  :       1    1     2    = 4
  137.  
  138. */
  139. int Legendre(int n, int p)
  140. {
  141.     int put=p, nr=0;
  142.     while(n/put>0)
  143.     {
  144.         nr+=n/put;
  145.         put*=p;
  146.     }
  147.     return nr;
  148. }
  149.  
  150. int main()
  151. {
  152.    
  153.     return 0;
  154. }
  155.  
Add Comment
Please, Sign In to add comment