0% found this document useful (0 votes)
8 views5 pages

Info Ex-1

The document contains code snippets for solving problems related to prime numbers, Fibonacci sequences, greatest common divisor (GCD), and least common multiple (LCM). The code uses for loops to iterate through numbers and test for divisibility or primality conditions.

Uploaded by

Dora Cobuz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Info Ex-1

The document contains code snippets for solving problems related to prime numbers, Fibonacci sequences, greatest common divisor (GCD), and least common multiple (LCM). The code uses for loops to iterate through numbers and test for divisibility or primality conditions.

Uploaded by

Dora Cobuz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Nr prim

for(i=2; i*i<=n; i++)


if(n%i==0)
ok=0;
if(ok==0)
cout<<"NU";
else
cout<<"DA";

Nr divizori

for(i=2; i<=ogl/2; i++)


{
if(ogl%i==0)
nrd=nrd++;
}

Primul divizor gasit (int)

for(i=2; i<=n/2 && d==0; i++)


{
if(n%i==0)
d=i;
}

Nr prime mai mici sau egale cu n

for(i=2;i<=n;i++)
{
ok=1;///pp ca e prim
///testam daca i este prim
for(j=2;j*j<=i;j++)
{
if(i%j==0)
ok=0;///nu e prim
}
if(ok==1)
{
cout<<i<<" ";
}

Primele n nr prime *

cin>>n;
k=n;
while(k>0)
{
///verificam daca x e prim
ok=1;
for(i=2;i*i<=x;i++)
{
if(x%i==0)
ok=0;
}
if(ok==1)
{
k--;
cout<<x<<" ";
}
x++;
}

Descompunere in factori primi

d=2;
cin>>n;
while(n>1)
{
while(n%d==0)
{
n=n/d;
cout<<d<<" ";
}
d++;
}

Descompunerea in factori primi + ex

int n,d=2, ex=0;


cin>>n;
while(n>1)
{
ex=0;
while(n%d==0)
{
n=n/d;
ex++;
}
if(ex!=0)
cout<<d<<' '<<ex<<' '<<endl;
d++;
if(d*d>n)
d=n;
}

Cmmdc

while(y!=0)
{
r=x%y;
x=y;
y=r;
}
cout<<x;

Cmmmc

cmmc=x*y;
Cmmdc;
cmmc=cmmc/x;
N nr din sirul recurent

int n, x=1, y=1, z, i;


cin>>n;
if(n==1)
cout<<1;
else
{
cout<<x<<' '<<y<<' ';
for(i=3;i<=n;i++)
{
z=x+y;
cout<<z<<' ';
x=y;
y=z;
}
}

Nr din sirul recurrent pana la n

int n, x=1, y=1, z, i;


cin>>n;
cout<<x<<' '<<y<<' ';
while (x+y<=n)
{
z=x+y;
cout<<z<<' ';
x=y;
y=z;

N apartine sirului

int n, x=1, y=1, z, i;


cin>>n;
while (x+y<=n)
{
z=x+y;
x=y;
y=z;
}
if(z==n)
cout<<"DA";
else
cout<<"NU";

Vecinii din fibonacci ai lui n

int n, i, f, a, b, ok, c, x=1, y=1, z, z2;


cin>>n;
while (x+y<n)
{
z=x+y;
x=y;
y=z;
}
x=1;
y=1;
do
{
z2=x+y;
x=y;
y=z2;
}
while(z2<=n);
cout<<z<<' '<<z2;

You might also like