lightoj1341唯一分解定理
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 bdenotes 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
唯一分解定理模板:
1 LL num_of_divisors(LL n) 2 { 3 LL s=1; 4 if(n==0) 5 return 0; 6 for(int j=0;j<w;j++) 7 { 8 LL tt=0; 9 while(n%prime[j]==0) 10 { 11 n/=prime[j]; 12 tt++; 13 } 14 s*=(tt+1); 15 if(n==1) 16 break; 17 } 18 if(n>1) 19 s*=2; 20 return s; 21 }
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 #define maxn 1000005 8 #define LL long long 9 LL prime[maxn], p[maxn]; 10 int w; 11 void find_prime() 12 { 13 w=0; 14 memset(p,0,sizeof(p)); 15 p[0]=p[1]=1; 16 for(int i=2;i<maxn;i++) 17 { 18 if(!p[i]) 19 { 20 prime[w++]=i; 21 for(int j=i+i;j<maxn;j+=i) 22 { 23 p[j]=1; 24 } 25 } 26 } 27 } 28 LL num_of_divisors(LL n) 29 { 30 LL s=1; 31 if(n==0) 32 return 0; 33 for(int j=0;j<w;j++) 34 { 35 LL tt=0; 36 while(n%prime[j]==0) 37 { 38 n/=prime[j]; 39 tt++; 40 } 41 s*=(tt+1); 42 if(n==1) 43 break; 44 } 45 if(n>1) 46 s*=2; 47 return s; 48 } 49 int main() 50 { 51 find_prime(); 52 int t; 53 LL a,b; 54 while(scanf("%d",&t)!=EOF) 55 { 56 for(int i=1;i<=t;i++) 57 { 58 scanf("%lld%lld",&a,&b); 59 printf("Case %d: ",i); 60 if(b>(LL)sqrt(a)) 61 printf("0\n"); 62 else 63 { 64 LL sum=num_of_divisors(a)/2; 65 for(int j=1;j<b;j++) 66 { 67 if(a%j==0) 68 { 69 sum--; 70 } 71 } 72 printf("%lld\n",sum); 73 } 74 } 75 } 76 return 0; 77 }