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.
Starts with a line containing-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 |
Output for Sample Input |
2 10 2 12 2 |
Case 1:1 Case 2:2 |
Application of the unique decomposition law: Ask for an approximate number of numbers greater than or equal to B. First, the total of approximately several numbers, and then the elimination of less than B can be. Consider that each factor has bi, then there is a (bi+1) choice.
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <string
> #include <iostream> #include <queue> #include <cmath> #include <map> #include <stack>
#include <bitset> using namespace std; #define REPF (I, A, b) for (int i = A; I <= B; + + i) #define REP (i, n) for (int i = 0; i < n; + + i) #d
Efine CLEAR (A, X) memset (A, x, sizeof a) typedef long long LL;
typedef pair<int,int>pil;
const int INF = 0X3F3F3F3F;
const int maxn=1e6+5;
BOOL VIS[MAXN+10];
int PRIM[MAXN/10];
LL A, B;
int t,cnt=0;
void Init () {for (Int. i=2;i*i<=maxn;i++) if (!vis[i]) for (int j=i*i;j<=maxn;j+=i) vis[j]=1;
for (int i=2;i<=maxn;i++) if (!vis[i]) prim[cnt++]=i;
} ll solve () {ll ans=1,temp=a;
if (a/b<b) return 0;
for (int i=0;i<cnt&&prim[i]*prim[i]<=a;i++) {int c=0;
while (a%prim[i]==0) {C + +; A/=prim[i];
} ans*= (c+1);
} if (a>1) ans<<=1;
Ans>>=1;//ans/2 kind of rectangle, if the other is a square, ans must be odd, ANS/2 can also remove this case for (int i=1;i<b;i++) if (temp%i==0) ans--;
return ans;
} int main () {int cas=1;
Init ();
cin>>t;
while (t--) {cin>>a>>b;
cout<< "Case" <<cas++<< ":" <<solve () <<endl;
} return 0;
}
Light OJ 1236:
Find The result of the following code:
Long long PAIRSFORMLCM (int n) {
Long long res = 0;
for (int i = 1; I <= n; i++)
for (int j = i; J <= N; j + +)
if (LCM (i, j) = = N) res++; LCM means least common multiple
return res;
}
A straight forward implementation of the code may time out. IF you analyze the code, you'll find that the code actually counts the number of pairs (i, J) for which LCM (i, j) = N and (i≤j). Input
Input starts with an integer T (≤200), denoting the number of test cases.
Each case is starts with a line containing an integer n (1≤n≤1014). Output
For each case, print the case number and the value returned by the function ' PAIRSFORMLCM (n) '.
Sample Input |
Output for Sample Input |
15 2 3 4 6 8 10 12 15 18 20 21st 24 25 27 29 |
Case 1:2 Case 2:2 Case 3:3 Case 4:5 Case 5:4 Case 6:5 Case 7:8 Case 8:5 Case 9:8 Case 10:8 Case 11:5 Case 12:11 Case 13:3 Case 14:4 Case 15:2 |
The logarithm of the LCM (I,J) (I<=j) is N: To calculate the prime decomposition, if BI is the power of the first prime, then for the two number of one of the power must be bi, another random, then for the first prime of the allocation scheme has (2*bi+1) species
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <string
> #include <iostream> #include <queue> #include <cmath> #include <map> #include <stack>
#include <bitset> using namespace std; #define REPF (I, A, b) for (int i = A; I <= B; + + i) #define REP (i, n) for (int i = 0; i < n; + + i) #d
Efine CLEAR (A, X) memset (A, x, sizeof a) typedef long long LL;
typedef pair<int,int>pil;
const int INF = 0X3F3F3F3F;
const int maxn=1e7+5;
BOOL VIS[MAXN+10];
int PRIM[MAXN/10];
int cnt=0;
void Init () {for (Int. i=2;i*i<=maxn;i++) if (!vis[i]) for (int j=i*i;j<=maxn;j+=i) vis[j]=1;
for (int i=2;i<=maxn;i++) if (!vis[i]) prim[cnt++]=i;
} LL T,n;
int main () {init (); int Cas=1;
scanf ("%lld", &t);
while (t--) {scanf ("%lld", &n);
LL Ans=1;
for (int i=0;i<cnt&&prim[i]*prim[i]<=n;i++) { if (n%prim[i]==0) {int c=0;
while (n%prim[i]==0) {C + +;
N/=prim[i];
} ans*= (2*c+1);
}} if (n>1) ans*=3;
printf ("Case%d:%d\n", cas++, (ans+1)/2);
} return 0;
}