#include <iostream>
unsigned perfectSquareLessOrEqual(unsigned n) {
unsigned sum = 0;
for (unsigned i = 1; (sum + i) <= n; i += 2)
sum += i;
return sum;
}
int main() {
unsigned x, y;
std::cin >> x >> y;
const unsigned a = perfectSquareLessOrEqual(x) + perfectSquareLessOrEqual(y);
const unsigned b = perfectSquareLessOrEqual(x + y);
if (a < b)
std::cout << "Petya gives paint to Vasya";
else if (a > b)
std::cout << "Petya leaves paint to himself";
else
std::cout << "Equal";
return 0;
}
Объяснение:
примерно так
uses crt;
var i,count:integer;
a:array[1..20] of integer;
begin
randomize;
count:=0;
for i:=1 to 20 do a[i]:=random(99)+1;
for i:=1 to 20 do write(a[i],' ');
for i:=1 to 20-1 do
begin
if (a[i+1]-a[i]=5) then inc(count); end;
writeln;
writeln(' count = ', count);
readln;
end.