版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sxy201658506207/article/details/84672739
给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数。
肯定是和面积的因子有关系了,边长都是面积值的 因子。
那么就可以算出面积值得所有因子,因为是让求得矩形得个数,当然是要<<1了,
还有个限制条件就是最小得边长要大于等于b得,
那么把小于b得因子减去,得到的值就是符合条件的对数了
2
10 2
12 2
Sample Output
Case 1: 1
Case 2: 2
#include <iostream>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
int prime[maxn];
bool notprime[maxn];
ll n,area;
void getprime(){
memset(prime,0,sizeof(prime));
memset(notprime,false,sizeof(notprime));
notprime[0]=notprime[1]=true;
for(int i=2;i<maxn;++i){
if(!notprime[i]) prime[++prime[0]]=i;
for(int j=1;j<=prime[0]&&prime[j]<=maxn/i;++j){
notprime[prime[j]*i]=1;
if(i%prime[j]==0)
break;
}
}
}
int solve(){
if(area/n<n)return 0;
int ans=1;
ll temp=area;
for(int i=1; area/prime[i]>=prime[i];++i){
int cnt=0;
if(area%prime[i]==0){
while(area%prime[i]==0){
area/=prime[i];
cnt++;
}
ans*=(cnt+1);
}
}
if(area>1)
ans<<=1;
ans>>=1;
//as an cloculsion:
//n have how many pairs of factors can be: n the number of factors divided by 2
for(int i=1;i<n;++i){// because of the other factor greater or equal n
if(temp%i==0)
--ans;
}
return ans;
}
int main(){
getprime();
int t;
scanf("%d",&t);//in>>t;
for(int ca=1;ca<=t;++ca){
scanf("%lld%lld",&area,&n);
printf("Case %d: %d\n",ca,solve());
}
return 0;
}