题意
给一对数字 a,b ,a是一个长方形的面积,问有多少种整数的边的组合可以组成面积为a的长方形,要求最短的边不得小于b
数据组数T<=4000, a,b<=10^12
Solution
暴力求肯定TLE
想想唯一分解定理:
\(X=\Pi_i^{P_i|X} P_i^{a_i}\)
则X的正因数个数为\(\Pi_i(a_i + 1)\)
因为题目中要求的是长方形,且最短边大于b
那么a / b < b时输出0就好,否则将A分解,求出它的约数个数。
又因为求出来的约数对数是无序的,所以要除以2,最后枚举b以内的减去就好
然而\(b<=\sqrt a,10^6*T好像会TLE,但是过了???\)
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e5 + 10), __(1e6 + 10);
IL ll Read(){
char c = '%'; ll x = 0, z = 1;
for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * z;
}
int prime[__], isprime[__], num;
ll a, b, ans;
IL void Prepare(){
for(RG int i = 2; i <= __; ++i){
if(!isprime[i]) prime[++num] = i;
for(RG int j = 1; j <= num && i * prime[j] <= __; ++j){
isprime[i * prime[j]] = 1;
if(!(i % prime[j])) break;
}
}
}
int main(RG int argc, RG char *argv[]){
Prepare();
for(RG int T = Read(), i = 1; i <= T; ++i){
a = Read(); b = Read(); ans = 1;
if(a / b < b) ans = 0;
else{
RG ll x = a;
for(RG int j = 1; j <= num && prime[j] * prime[j] <= x; ++j){
if(x % prime[j]) continue;
RG ll cnt = 0;
while(!(x % prime[j])) ++cnt, x /= prime[j];
ans *= cnt + 1;
}
if(x > 1) ans *= 2;
ans >>= 1;
for(RG int i = 1; i < b; ++i) if(a % i == 0) --ans;
}
printf("Case %d: %lld\n", i, ans);
}
return 0;
}