Aladdin and the Flying Carpet
Time Limit:3000MS
Memory Limit:32768KB
64bit IO Format:%LLD &%llusubmit Status Practice lightoj 1341Appoint Description:System Crawler (2016-07-08)
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
00a2
12 2
Sample Output
Case 1:1
Case 2:2
1. How many approximate numbers are there:
First decompose factorization
The number of factors is 4,2,1, respectively.
So the number of numbers is (4+1) * (2+1) * (+) =5*3*2=30
eg
First decompose factorization
720=24*32*51
The number of factors is 4,2,1, respectively.
So the number of numbers is (4+1) * (2+1) * (+) =5*3*2=30
2. All the sum of the approximate:
Approximate sum of 2004:1, 2, 3, 4, 6, 12, 167, 334, 501, 668, 1002, 2004 = 4704
How do you ask for a sum of all the numbers?
First, the arithmetic basic theorem is applied to simplify the product of prime exponent.
X = A1^k1 * A2^K2........AN^KN
Sum of all primes of x (1+A1 + a1^2...a1^k1) * (1+A2 + a2^2...a2^k2) * ... (1+an + an^2...an^kn) indicates
Such as:
2004 = 2^2 * 3 *167
2004 Sum of all factors (1 + 2 + 2^2) * (1 + 3) * (1 + 167) = 4704;
When the program is implemented, you can use geometric series to quickly request 1 + A1 + a1^2 + ... a1^n;
Ideas:
The number of each mass factor is calculated, and then the approximate number of it is calculated by a formula. If b * B > A, then the value must be 0, the remainder can be enumerated B, deleted. But I think the enumeration should be dead,
But it didn't hang.
/** author:sweat122 * Created TIME:2016/7/11 14:53:29 * File Name:main.cpp*/#include<Set>#include<map>#include<queue>#include<stack>#include<cmath>#include<string>#include<vector>#include<cstdio>#include<time.h>#include<cstring>#include<iostream>#include<algorithm>#defineINF 1<<30#defineMOD 1000000007#definell Long Long#defineLson l,m,rt<<1#defineKey_value Ch[ch[root][1]][0]#defineRson m+1,r,rt<<1|1#definePi ACOs (-1.0)using namespacestd;Const intMAXN =1000050;intNotprime[maxn],prime[maxn],cnt;ll A, b;voidinit () {CNT=0; memset (Prime,0,sizeof(prime)); memset (Notprime,0,sizeof(Notprime)); for(inti =2; I < MAXN- -; i++){ if(!Notprime[i]) {prime[cnt++] =i; } for(intj =0; J < cnt && 1LL * PRIME[J] * I < MAXN- -; J + +) {Notprime[prime[j]* I] =1; if(i% prime[j] = =0) Break; } }}intMain () {intT,case =0; Init (); scanf ("%d",&t); while(t--) {scanf ("%lld%lld",&a,&b); ll ans=1; ll x=A; for(inti =0; I < CNT; i++){ if(Prime[i] > x) Break; if(x% prime[i] = =0){ intnum =0; while(x% prime[i] = =0) {num+=1; X/=Prime[i]; } ans*= (num +1); } } if(X >1) Ans *= (1+1); Ans/=2; if(b * b >a) {printf ("Case %d:%lld\n", ++case,0); } Else{ for(inti =1; I < b; i++){ if(a% i = =0) ans-=1; } printf ("Case %d:%lld\n",++Case,ans); } } return 0;}
Lightoj 1341 Unique decomposition theorem