Fork me on GitHub

[XR-4]题

[XR-4]题

[XR-4]题

$gtmd \: xht$

其实这是个好题.

直接化式子好啦.

$$y^2 - x^2 = ax + b $$

$$x^2 + ax + b = y^2 $$

因为一定有 $y\ge x$ , 所以令 $y = x + t,t\in N$.

$$x^2 + ax + b = x^2 + 2tx + t^2$$

$$ax + b = 2tx + t^2$$

$$(a-2t)x=t^2-b$$

$$x=\cfrac{t^2-b}{a-2t}$$

于是枚举 $t$ 即可.

那么枚举下界很清晰,就是 $0$ , 上界是 $max{\sqrt{b} , \cfrac{a}{2}}$

因为上界肯定是这俩中的一个,所以干脆取个 $max$ .

你发现, $x$ 这个玩意儿显然不能为负(因为题目要的是非负解).

所以分子分母必须同号.

然后,分母显然不能为 $0$.(除非分子也是 $0$ .)

事实上,分子分母都为 $0$ 的时候是答案是 $inf$.

完了.

$Code:$

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define pii pair < int , int >
#define one first
#define two second
#define rint read<int>
#define int long long
#define pb push_back
#define db double
#define ull unsigned long long
#define lowbit(x) ( x & ( - x ) )

using std::queue ;
using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
using std::swap ;
using std::sort ;
using std::unique ;
using std::greater ;

template < class T >
inline T read () {
T x = 0 , f = 1 ; char ch = getchar () ;
while ( ch < '0' || ch > '9' ) {
if ( ch == '-' ) f = - 1 ;
ch = getchar () ;
}
while ( ch >= '0' && ch <= '9' ) {
x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
ch = getchar () ;
}
return f * x ;
}

int a , b , sqr , ans ;
bool f ;

signed main (int argc , char * argv[]) {
a = rint () ; b = rint () ; sqr = (int)sqrt ( b ) ;
sqr = max ( sqr , ( a >> 1ll ) ) ; f = false ;
rep ( i , 0ll , sqr ) {
if ( f ) break ;
int up = i * i - b ;
int down = a - i * 2ll ;
if ( up == 0ll && down == 0ll ) f = true ;
if ( down == 0ll ) continue ;
if ( up / down < 0ll ) continue ;
if ( up % down == 0ll ) ++ ans ;
}
if ( ! f ) printf ("%lld\n" , ans ) ;
else puts ("inf") ;
system ("pause") ; return 0 ;
}