http://codeforces.com/contest/495/problem/B
a mod x = b等价于(a-b)%x=0那么就容易思考解决,不过我没想到这个也做出来了!
AC代码:
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int a,b; cin >> a >> b;
if(a < b){
cout << "0" << endl;
return 0;
}
if(a == b){
cout << "infinity" << endl;
return 0;
}
int t = a - b;
int ans = 0;
for(int k=1; k<=sqrt(t); k++){
if(t % k == 0 && (t / k > b)) ans++;
if(t % k == 0 && k*k != t && k > b) ans++;
}
cout << ans << endl;
//system("pause");
return 0;
}