#include <iostream>
#include<vector>
using namespace std;
int square(int x){
for (int i = 1; i <= 45; ++i){
if (i * i <= x){
continue;
}
return (i - 1) * (i - 1);
int main()
{
int x, y, xwas, ywas, xywas;
cin >> x >> y;
xwas = square(x);
ywas = square(y);
xywas = square(x + y);
if (xwas + ywas < xywas){
cout << "Petya gives paint to Vasya";
else if (xwas + ywas == xywas){
cout << "Equal";
else {
cout << "Petya leaves paint to himself";
return 0;
Объяснение:
Решение не моё, но вдруг понадобиться)
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";
#include <iostream>
#include<vector>
using namespace std;
int square(int x){
for (int i = 1; i <= 45; ++i){
if (i * i <= x){
continue;
}
return (i - 1) * (i - 1);
}
}
int main()
{
int x, y, xwas, ywas, xywas;
cin >> x >> y;
xwas = square(x);
ywas = square(y);
xywas = square(x + y);
if (xwas + ywas < xywas){
cout << "Petya gives paint to Vasya";
}
else if (xwas + ywas == xywas){
cout << "Equal";
}
else {
cout << "Petya leaves paint to himself";
}
return 0;
}
Объяснение:
Решение не моё, но вдруг понадобиться)
Объяснение:
#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;
}