#include #include using namespace std; //nr prim int prim (int x) { if(x<2) return 0; if(x%2==0&&x!=2) return 0; for(int d=3;d*d<=x;d=d+2) { if(x%d==0) return 0; } return 1; } int cmmdc_s(int a,int b) { while(a!=b) { if(a>b) a=a-b; else b=b-a; } return a; } int cmmdc_euclid(int a,int b) { int r; while(b!=0) { r=a%b; a=b; b=r; } return a; }
// 121, 11 int palindrom(int x) { int aux,og=0; aux=x; while(aux>0) { og=og*10+(aux%10); aux=aux/10; } if(x==og) return 1; return 0; } // 25,36,81 int patratperfect(int x) { int r; r=sqrt(x); if(r*r==x) return 1; return 0; } //x=29 2+9=11 1+1=2; int cifra_control(int x) { if(x%9==0) return 9; //9,18,27 return x%9; } //n=100;s=1+2+4+5+10+20+25+50+100=217 long long sumdiv(int x) { long long s=0,d; for(d=1;d*d<x;d++) { if(x%d==0) s=s+d+x/d; } if(d*d==x) s=s+d; return s; }
//descompunere in factori primi //suma divizorilor primi //n=100 s=2+5=7 int sumdiv_prim(int x) { int s=0,d=2,exp; while(x>1) { exp=0; while(x%d==0) { exp++; x=x/d; } if(exp!=0) s=s+d; if(d==2) d=3; else d=d+2; } return s; } //n=1232 c=2 (dublam cifra c) m=122322 //vom construi un alt nr m int dublare(int x,int c) { int m=0,p=1; while(x>0) { m=(x%10)*p+m; p=p*10; if(c==x%10) { m=(x%10)*p+m; p=p*10; } x=x/10; } return m; }
//n=1232 c=2 (dupa eliminare) m=13 int elim_cif(int x,int c) { int m=0,p=1; while(x>0) { if(c!=x%10) { m=(x%10)*p+m; p=p*10; } x=x/10; } return m; } //numarul de 0-uri de la sfarsitul lui n! //25! are 6 0-uri la sfarsit n/5+n/25+n/125…. int nr_zero(int x) { int p=5,s=0; while(p<=x) { s=s+x/p; p=p*5; } return s; } //al n-lea termen al sirului Fibonacci //n=8 1 1 2 3 5 8 13 21 int fibo (int n) { int a=1,b=1,c; if(n<2) return 1; for(int i=3;i<=n;i++) { c=a+b; a=b; b=c; } return c; } //nr de 1 in baza 2 //4 este 100 in baza 2 int baza2 (int n) { int nr=0;
while(n>0) { if(n%2==1) nr++; n=n/2; } return nr; } //citire vector //n=5 28 5 -7 4 32 void citire (int &n, int v[]) { int i; cin>>n; for(i=1;i<=n;i++) cin>>v[i]; } //citim pana la aparitia lui 0 void citire(int &n, int v[]) { n=0; int x; cin>>x; while(x!=0) { v[++n]=x; cin>>x; } } void afisare (int n,int v[]) { int i; for(i=1;i<=n;i++) cout<
for(j=i+1;j<=n;j++) { if(v[i]>v[j]) { aux=v[i]; v[i]=v[j]; v[j]=aux; } } } void sort_buble (int n,int v[]) { int ok,i; do{ ok=1; for(i=1;ix)
{
{ v[j+1]=v[j]; j--;
int i=1,j=1; n=0; while(i<=n1&&j<=n2) { if(v1[i]
} v[j+1]=x; n++; } //separarea elementelor pare de cele impare void par_impar (int n,int v[]) { int i=1,j=n,aux; while(i<=j) { while(v[i]%2==0&&i<=n) i++; while(v[j]%2!=0&&j>=0) j--; if(i<=j) { aux=v[i]; v[i]=v[j]; v[j]=aux; i++; j--; } } } void secventa_para (int n,int v[],int &inc, int &sf, int &lmax) { int lc=0,lmax,i; for(i=1;i<=n;i++) { if(v[i]%2==0) lc++; else lc=0; if(lc>lmax) { lmax=lc; sf=i; inc=i-lc+1; } } } //cei doi vectori trebuie sa fie sortati crescator void interclasare (int n1,int v1[],int n2,int v2[],int &n,int v[])
} //primul vector este sortat crescator, iar al doilea descrescator void interclasare (int n1,int v1[],int n2,int v2[],int &n,int v[]) { int i=1,j=n2; n=0; while(i<=n1&&j>=1) { if(v1[i]=1) v[++n]=v2[j--]; } int main() { return 0; }