At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving each other one candy more than they received in the previous turn.
This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Single line of input data contains two space-separated integers a, b (1 ≤ a, b ≤ 109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
1 1
Valera
7 6
Vladik
Illustration for first test case:
Illustration for second test case:
题意
对A和B两个数轮流操作,第i轮对A删除2*i-1的值,对B删除2*i的值,问哪个谁先小于0? A先手。
只需要根据等差数列求和列出两个不等式即可:
对于A来说,直到第i轮消耗的数量为:i*i<=a
对于B来说,直到第i轮消耗的数量为:i*(i+1)<=b
因此,只要求最大的ia和ib即可,二者中小的先消耗光,而相等的时候答案就输出A,因为A先手。
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,x,y;
int main()
{
cin>>a>>b;
for(x=0;x*x<=a;x++);
for(y=0;y*(y+1)<=b;y++);
if(x<=y) cout<<"Vladik";
else cout<<"Valera";
return 0;
}