Problemele de pe pbinfo:
-Suma 2(491);
-numarPIE(498);
-Numarare5(499);
-Numarare4(496);
Va ROGGGGGGG!!!!!!!80 DE PUNCTE!
Macar 2 probleme.
Răspunsuri la întrebare
----------- suma2 ------------
#include <iostream>
using namespace std;
int a[1001];
int main()
{
int n, i, p=-1, u=-1, s=0;
cin >> n;
for (i=1; i<=n; ++i)
{
cin >> a[i];
if (a[i]%2==0)
{
if (p==-1) {p=i; u=i;}
if (p!=-1) u=i;
}
}
if (p==-1) cout << "NU EXISTA";
else
{
for (i=p; i<=u; ++i) s+=a[i];
cout << s;
}
return 0;
}
------------------498 numarare PIE ----------------
#include <iostream>
using namespace std;
int v[1001];
bool pie(int a, int b)
{
int i, p=1;
if (a==1 || b==1) p=1;
else
{
if ((a==2 && b==2)||(a==b)) p=0;
else
{
if (a<b) { int t=a; a=b; b=t;}
for (i=2;i*i<=a && p; ++i)
if (a%i==0)
{ if (b%i==0) {p=0;}
else if (b%(a/i)==0) p=0; }
}
}
return p;
}
int main()
{
int n, j, k, C=0;
cin >> n;
for (j=1; j<=n; ++j) cin >> v[j];
for (j=1; j<n; ++j)
for (k=j+1; k<=n; ++k)
if (pie(v[j], v[k])) ++C;
cout << C << endl;
return 0;
}
------------ 499 numarare 5 -----------------
#include <iostream>
using namespace std;
int v[201];
int sumacif(int m)
{
int s=0;
while (m!=0)
{
s=s+m%10; m=m/10;
}
return s;
}
int main()
{
int n, i, j, k=0;
cin >> n;
for (i=1; i<=n; ++i) cin >> v[i];
for (i=1; i<n; ++i)
for (j=i+1; j<=n; ++j)
if (sumacif(v[i])==sumacif(v[j])) ++k;
cout << k;
return 0;
}
------------ 496 numarare4 ---------------
#include <iostream>
using namespace std;
short v[201];
int main()
{
short n, i, a, b, c=0, r;
cin >> n;
for (i=1; i<=n; ++i) cin >> v[i];
for (i=1; i<n; ++i)
{
a=v[i]; b=v[n];
while (b!=0)
{
r=a%b; a=b; b=r;
}
if (a==1) ++c;
}
cout << c;
return 0;
}