Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define N 205
- using namespace std;
- /**
- Algoritmi elementari sub forma de functii
- */
- void Divizori(int n) ///afisare O(n/2)
- {
- cout<<1<<" ";
- for(int d=2;d<=n/2;d++)
- if(n%d==0) cout<<d<<" ";
- if(n!=1) cout<<n;
- /// cout<<"\n";
- }
- int SumaDiv(int n) ///O(sqrt(n))
- {
- int s=0,d;
- for(d=1;d*d<n;d++)
- if(n%d==0)s+=d+n/d;
- if(d*d==n) s+=d;
- return s;
- }
- int Cmmdc(int a, int b)///
- {
- int r;
- while(b!=0)
- {
- r=a%b;
- a=b;
- b=r;
- }
- return a;
- }
- void Cmmdc(int a, int b, int &sol)///supraincarcare functie si parametru de iesire
- {
- int r;
- while(b!=0)
- {
- r=a%b;
- a=b;
- b=r;
- }
- sol=a;
- }
- bool Prim(int x) ///O(sqrt(n)/2)
- {
- if(x<2) return 0;
- if(x==2) return 1;
- if(x%2==0) return 0;
- for(int d=3;d*d<=x;d+=2)
- if(x%d==0)return 0;
- return 1;
- }
- void DescFactori(int n)
- {
- int d=2,p;
- while(n!=1)
- {
- p=0;
- while(n%d==0) p++,n/=d;
- if(p) cout<<d<<" "<<p<<"\n";
- if(d*d<n)d++;
- else d=n;
- }
- /// cout<<"\n";
- }
- int IndicatorEuler(int n)
- {
- double phi=n;
- int p, d=2;
- while(n!=1)
- {
- p=0;
- while(n%d==0) p++,n/=d;
- if(p) phi*=(d-1.0)/d;
- if(d*d<n)d++;
- else d=n;
- }
- return int(phi);
- }
- int Fibo(int n) ///al n termen
- {
- int f1=1,f2=1,f;
- if(n==1 || n==2) return f1;
- for(int i=3;i<=n;i++)
- {
- f=f1+f2;
- f1=f2;
- f2=f;
- }
- return f;
- }
- ///B10-Bq 10(10)= 1010(2)
- long long B10BQ(int n10, int q)
- {
- long long nq=0, p=1;
- while(n10!=0)
- {
- nq=nq+p*(n10%q);
- p*=10;
- n10/=q;
- }
- return nq;
- }
- ///bq-b10
- int BQB10(long long nq, int q)
- {
- int n10=0, p=1;
- while(nq!=0)
- {
- n10=n10+p*(nq%10);
- p*=q;
- nq/=10;
- }
- return n10;
- }
- ///formula lui Legendre
- /**
- cate valori de p se gasesc in n!=1*2*3*4*5*...*n
- np=[n/p]+[n/p^2]+[n/p^3]+...
- 1 2 3 4 5 6 7 8 9 10
- 2 : 1 2 1 3 1 = 8
- 5 : 1 1 = 2
- 3 : 1 1 2 = 4
- */
- int Legendre(int n, int p)
- {
- int put=p, nr=0;
- while(n/put>0)
- {
- nr+=n/put;
- put*=p;
- }
- return nr;
- }
- int main()
- {
- return 0;
- }
Add Comment
Please, Sign In to add comment