题意:a % x == b,求符合条件的x有几个
数学:等式转换为:a == nx + b,那么设k = nx = a - b,易得k的约数(>b)的都符合条件,比如a=25 b=1,那么24,12, 8, 6, 4, 3, 2都可以,所以只要求出k的约数有几个就可以了,a <= b的情况要特判
/************************************************ * Author :Running_Time * Created Time :2015-8-19 18:49:21 * File Name :A.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int MAXN = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int divisor(int n, int b) { int ret = 0; for (int i=1; i*i<=n; ++i) { if (n % i == 0) { if (i > b) ret++; if (n / i != i && n / i > b) ret++; } } return ret; } int main(void) { //Codeforces Round #282 (Div. 2) B. Modular Equations int a, b; scanf ("%d%d", &a, &b); if (a < b) { puts ("0"); return 0; } if (a == b) { puts ("infinity"); return 0; } int ans = divisor (a - b, b); printf ("%d\n", ans); return 0; }