http://lightoj.com/volume_showproblem.php?problem=1341
Aladdin and the Flying Carpet
Time Limit:3000MS
Memory Limit:32768KB
64bit IO Format:%LLD &%llusubmit Status Practice Lightoj 1341
Description
It's said that Aladdin had to solve seven mysteries before getting the magical Lamp which summons a powerful Genie. Here we is 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 s Trange 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 is a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped and not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.
Now all given the area of the carpet and the length of the minimum possible side of the carpet, your task was to find H OW many types of carpets is possible. For example, the area of the carpet, and the minimum possible side of the carpet are 2, then there can are both types of C Arpets 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 the integers: ab(1≤b≤a≤1012) where a den OTEs 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
The main idea: to give the rectangular area AB, and the minimum value of the edges that make up the rectangle, ask that this area is AB rectangle has several
For example 12 2, the rectangular area is 12, the smallest side that makes up such a rectangle is 2, a total of 2 such rectangles (2, 6), (3, 4) (these edges are greater than or equal to 2, where (2,6) and (6,2) are the same)
This problem uses the only decomposition theorem: n = p1^a1*p2^a2*p3^a3* ... *pn^an (where p1, p2 、... pn is n, a1, A2 、... 、 an exponent of factor respectively)
n the number of factors M = (1 + A1) * (1 + A2) * (1 + A3) *...* (1 + an);
The number of factors of AB is calculated by the unique decomposition theorem, but the number of factors required to satisfy the condition is the logarithm of the factor, so the final factor needs to be divided by 2, and then the unsatisfied minus
The problem is to use a number of filter primes to shorten the time (reduce cycle times) to prevent the tle
#include <stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#include<algorithm>using namespaceStd;typedefLong Longll;Const intN = 1e6 +Ten;intPrime[n], K;BOOLIsprime[n];voidPrime () {k=0; memset (IsPrime,true,sizeof(IsPrime)); isprime[1] =false; for(inti =2; i < N; i++) { if(Isprime[i]) {prime[k++] =i; for(intj =2; I * J < N; J + +) Isprime[i* j] =false; } }}//Prime number Screeningll Solve (ll N) {ll ans=0, sum =1; for(LL i =0; I < K && Prime[i] * Prime[i] <= N; i++) { if(n% prime[i] = =0) {ans=0; while(n% prime[i] = =0) {ans++; N/=Prime[i]; } Sum*= (1+ans); } } if(N >1) Sum*=2; returnsum;}//number of factors to find nintMain () {Prime (); intT, x =0; ll AB, a, num; scanf ("%d", &t); while(t--) {x++; scanf ("%lld%lld", &ab, &a); if(AB < A *a) {printf ("Case %d:0\n", x); Continue; } num=solve (AB); Num/=2; for(LL i =1; i < A; i++) if(ab% i = =0) Num--;//subtract an edge less than aprintf"Case %d:%lld\n", x, num); } return 0;}
Lightoj 1341-aladdin and the Flying Carpet (unique decomposition theorem + prime number screening)