Test instructions gives you a number n to satisfy the LCM (A, b) = = N, the number of a <= b
It is easy to know that N is a, all the elements of B are taken in a, b the product of the larger exponent
The n is decomposed into the form of the prime exponent product n =π (Pi^ei) then for each factor pi pi in the exponent AI of a A, BI has at least one equal to PI and the other less than or equal to Pi
The size of a and b for each factor pi is not considered first
1. In a the index AI = = ei so pi in B index is preferable [0, ei] All the numbers have EI + 1 cases
2. In a the index AI < ei is ai in [0, ei) then pi in B index can only take EI in the case of EI
Then there are 2*ei + 1 conditions for each element factor (a, B) has π (2*ei + 1) Considering the size of the case except (n, N) all occurrences two times so satisfied a<=b ( Pi (2*ei + 1)/2 + 1 x
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e7 + 5; int pme[
N/10], M;
BOOL Vis[n];
void Initprime ()//linear sieve {m = 0;
for (int i = 2; i < N; ++i) {if (!vis[i]) pme[m++] = i;
for (int j = 0; J < m && Pme[j] * i < N; ++j) {vis[pme[j] * i] = 1;
if (i% pme[j] = = 0) break;
}}} int main () {initprime ();
ll N, ans, C;
int T, cas = 0;
scanf ("%d", &t);
while (t--) {scanf ("%lld", &n);
ans = 1;
for (int i = 0; i < m; ++i) {if (ll (Pme[i]) *pme[i] > N) break;
c = 0;
while (n% pme[i] = = 0) {n/= pme[i];
++c;
} if (c) ans *= c * 2 + 1;
} if (n > 1) ans *= 3;
printf ("Case%d:%lld\n", ++cas, ANS/2 + 1);
} return 0; }
1236-pairs Forming LCM
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 |