标签:types using imu lamp ica oss scanf stream ret
It‘s said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.
Aladdin was about to enter to a magical cave, led by the evil sorcerer who disguised himself as Aladdin‘s uncle, found a strange magical flying carpet at the entrance. There were some strange creatures guarding the entrance of the cave. Aladdin could run, but he knew that there was a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped, but not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.
Now you are given the area of the carpet and the length of the minimum possible side of the carpet, your task is to find how many types of carpets are possible. For example, the area of the carpet 12, and the minimum possible side of the carpet is 2, then there can be two types of carpets and their sides are: {2, 6} and {3, 4}.
Input
Input starts with an integer T (≤ 4000), denoting the number of test cases.
Each case starts with a line containing two integers: a b (1 ≤ b ≤ a ≤ 1012) where a denotes the area of the carpet and b denotes the minimum possible side of the carpet.
Output
For each case, print the case number and the number of possible carpets.
Sample Input
2
10 2
12 2
Sample Output
Case 1: 1
Case 2: 2
题目大意 就是给你一个面积N和一个可能的最小边m,问你满足条件的组合有多少个(不能是正方形)
思路: 先求出一个有多少个因子,然后除以2 就可以判断一共能组成多少对(前提是不考虑方形)然后暴力求出小于m的油多少对
减去就可以了 (如果考虑方形的话还要判断 给出的n是否为一个数的平方,如果是的话sum++,否则就按原来处理)
必须要打表 不然会TLE
#include<iostream> #include<cstring> #include<cstdio> #include<vector> #include<map> using namespace std; typedef long long ll; const int N=1E6+57; const int MAX=1e6+57; ll prime[N]; bool p[N]={1,1,0}; int k=0; void pre(){ for(ll i=2;i<=MAX;i++){ if(p[i]==0){ prime[k++]=i; for(ll j=i+i;j<=MAX;j+=i){ p[j]=1; } } } } ll count(ll x){ if(x==0 ) return 0; ll i=0; ll sum=1; while(prime[i]<x &&i<k){ ll t=0; if(x%prime[i]==0){ while(x%prime[i]==0){ x=x/prime[i]; t++; } sum*=t+1; } i++; } if(x>1) sum*=2; return sum; } int main(){ pre(); int t,kk=0; scanf("%d",&t); while(t--){ kk++; ll n,m; scanf("%lld%lld",&n,&m); if(m*m>=n){ printf("Case %d: 0\n",kk); continue ; } ll sum=count(n); sum=sum/2; for(ll i=1;i<m;i++){ if(n%i==0) sum--; } printf("Case %d: %lld\n",kk,sum); } return 0; }
E - Aladdin and the Flying Carpet
标签:types using imu lamp ica oss scanf stream ret
原文地址:https://www.cnblogs.com/Accepting/p/11343265.html