(CodeForces) B. Modular Equations

0

If we need to find the number of divisors of a number n, we can do it in O(\sqrt n).

 

If there exist any divisor which is greater than \sqrt n, then there must be a divisor less than \sqrt n, such that this two numbers create number n by multiplication. So, we only need to loop from 1 to \sqrt n to find out all divisors.


// link: http://codeforces.com/contest/495/problem/B
/****************************************************************
   ▄█    █▄       ▄████████    ▄████████  ▄█  ▀█████████▄
  ███    ███     ███    ███   ███    ███ ███    ███    ███
  ███    ███     ███    ███   ███    █▀  ███   ███    ███
 ▄███▄▄▄▄███▄▄   ███    ███   ███        ███  ▄███▄▄▄██▀
▀▀███▀▀▀▀███▀  ▀███████████ ▀███████████ ███ ▀▀███▀▀▀██▄
  ███    ███     ███    ███          ███ ███    ███    ██▄
  ███    ███     ███    ███    ▄█    ███ ███    ███    ███
  ███    █▀      ███    █▀   ▄████████▀  █▀   ▄█████████▀
****************************************************************/



#include<bits/stdc++.h>


#define FOR(i, s, e) for(int i=s; i<e; i++)
#define loop(i, n) FOR(i, 0, n)
#define sf scanf
#define pf printf
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define ll long long
#define dd double
#define all(v) v.begin(), v.end()
#define PI acos(-1.0)
#define mem(ara, value) memset(ara, value, sizeof(ara))
#define paii pair<int, int>
#define pall pair<ll, ll>
#define SZ(a) int(a.size())
#define read(nm) freopen(nm, "r", stdin)
#define write(nm) freopen(nm, "w", stdout)

#define dump(x) cerr<<#x<<" = "<<x<<endl
#define debug(args...) cerr,args; cerr<<endl;
using namespace std;


template<typename T>
ostream& operator<<(ostream& output, vector<T>&v)
{
    output<<"[ ";
    if(SZ(v))
    {
        output<<v[0];
    }
    FOR(i, 1, SZ(v))
    {
        output<<", "<<v[i];
    }
    output<<" ]";
    return output;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& output, pair<T1, T2>&p)
{
    output<<"( "<<p.fr<<", "<<p.sc<<" )";
    return output;
}




template<typename T>
ostream& operator,(ostream& output, T x)
{
    output<<x<<" ";
    return output;
}





//Header ends here



int countDivisor(ll num, ll greaterThan)
{
    ll root = sqrt(num);
    //dump(root);

    int cnt = 0;

    for(ll i = 1; i < root; i++)
    {
        if((num%i) == 0)
        {
            //dump(i);
            if(i > greaterThan)
                cnt ++;

            if((num/i) > greaterThan)
                cnt++;
        }
    }

    ll componentOfRoot = num/root;

    if((num%root) == 0 && root > greaterThan)
        cnt++;

    if(root != componentOfRoot && (num%componentOfRoot) == 0 && componentOfRoot > greaterThan)
        cnt++;



    return cnt;






}

int main()
{
    ll a, b;

    cin>>a>>b;

    if(a == b)
    {
        cout<<"infinity"<<endl;
    }
    else if(a < b)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<countDivisor(a-b, b)<<endl;
    }





}