zoukankan      html  css  js  c++  java
  • [XR-4]题

    [XR-4]题

    [XR-4]题

    (gtmd : xht)

    其实这是个好题.

    直接化式子好啦.

    [y^2 - x^2 = ax + b ]

    [x^2 + ax + b = y^2 ]

    因为一定有 (yge x) , 所以令 (y = x + t,tin 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:)

    #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
    " , ans ) ;
        else puts ("inf") ;
        system ("pause") ; return 0 ;
    }
    
  • 相关阅读:
    i--和--i的区别
    Visual studio 常用快捷键
    QFNU-ACM 2020.10.23
    QFNU-ACM 2020.10.16 Trating and ACM 实验室2020.10.17天梯赛练习*3
    ACM 实验室2020.10.10天梯赛练习*2
    第十届山东省ACM省赛复现补题报告
    ccpc总结
    2020.06.09——习题训练五
    2020.06.01——习题训练4
    2020年-05-26-习题训练三
  • 原文地址:https://www.cnblogs.com/Equinox-Flower/p/11712322.html
Copyright © 2011-2022 走看看