I. 1.
a. x % 2 == 0 && (y + 1) % 2 != 0
I. 2.
d. n = 720721 si c = 7
I. 3.
d. m[42][57]
I. 4.
b. 1, 2, 3, 1
I. 5.
c. 8
II. 2.
a. 1 1 1 1 1 2 1 1 2 1
b. 6, 15
c.
#include <iostream>
using namespace std;
int x, y, nr, i;
int main(){
cin>>x>>y;
if(x > y){
int aux = x;
x = y;
y = aux;
}
nr = 1;
for(i = y; i >= x; i --){
cout<<1;
if(nr >= x){
cout<<2;
}
nr = nr * 3;
cout<<1;
}
return 0;
}
d.
CITESTE x, y
DACA x > y ATUNCI x < > y
i <- y
CAT TIMP i >= x EXECUTA
SCRIE 1
DACA nr >= x ATUNCI
SCRIE 2
nr <- nr * 3
SCRIE 1
II. 2.
(ciocarlie, scatiu), (privighetoare, scatiu)
II. 3.
fs.a = f.b * 2020 - 2021 * f.b
fs.b = 2021 * f.b
III. 1.
void divPrim(int n, int & s){
s = 0;
int cnt = 0;
while(n % 2 == 0){
cnt ++;
n /= 2;
}
if(cnt % 2 == 1)
s += 2;
for(int i = 3; i <= n; i += 2){
if(n % i == 0){
bool prim = true;
for(int d = 3; d * d <= i; d += 2)
if(i % d == 0)
prim = false;
if(prim == true){
cnt = 0;
while(n % i == 0){
cnt ++;
n /= i;
}
if(cnt % 2 == 1)
s += i;
}
}
}
}
III. 2.
#include <cstring>
#include <iostream>
#include <cctype>
using namespace std;
int n, k, sz = -1;
char sol[25][15];
int main(){
cin>>n>>k;
for(int i = 1; i <= n; i ++){
char s[10];
cin>>s;
if(strchr("aeiou", s[strlen(s) - 1])){
sz++;
strcpy(sol[sz], s);
}
}
if(sz >= k){
for(int i = 0; i < k; i ++)
cout<<sol[i]<<"\n";
}
else{
cout<<"nu exista";
}
return 0;
}
III. 3.
a.
Algoritmul proiectat afla puterea p a lui x astfel incat sa putem extrage
sufixul din sirul dat
Parcurgem fisierul prin variabila y, iar variabila pre reprezinta variabila
precedenta a lui y, daca atat sufixul precedent cat si cel curent sunt egale cu x
atunci am gasit o noua solutie
Complexitate de timp : O(n)
Complexitate de memorie : O(1).
b.
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("bac.txt");
int p = 1, x, y, pre = -1, suf, a = -1, b = -1;
int main(){
in>>x;
int cop = x;
while(cop){
p *= 10;
cop /= 10;
}
while(in>>y){
if(pre != -1 && pre % p == x && y % p == x)
a = pre, b = y;
pre = y;
}
if(a != -1){
cout<<a<<" "<<b;
}
else{
cout<<"nu exista";
}
return 0;
}