Now there is a number x, 1 ≤ x ≤ n, which tells you n. You can guess a number y each time. If x = y, it ends. Otherwise, gcd (x, y) is returned ), you can guess the answer only a few times.
Input
The input file contains several test cases, each of them as described below.
The input contains one integer n, 2n10000.
Output
For each test case, write to the output on a line by itself.
Output one integer -- the number of guesses Andrew will need to make in the worst case.
Sample Input
6
Sample Output
2
First, we group all the elements within n, and each time we ask for the product of a group of prime numbers -- this number is determined based on the nature of Gcd.
Each greedy match is a large prime number and a bunch of small prime numbers (rightmost X leftmost)
[Cpp]
# Include <cstdio>
# Include <cstring>
# Include <algorithm>
# Include <functional>
# Include <iostream>
# Include <cstdlib>
# Include <cmath>
Using namespace std;
# Define MAXN (10000)
# Define eps (1e-9)
# Define For (I, n) for (int I = 1; I <= n; I ++)
# Define ForD (I, n) for (int I = n; I --)
# Define Fork (I, k, n) for (int I = k; I <= n; I ++)
Int n, a [MAXN], size = 0;
Bool B [MAXN];
Int main ()
{
Memset (B, 0, sizeof (B); B [1] = 1;
Fork (I, 2, MAXN)
{
If (! B [I]) B [I] = 1, a [++ size] = I;
For (j, size)
{
If (I * a [j]> MAXN) break;
B [I * a [j] = 1;
If (! I % a [j]) break;
}
}
// For (I, 100) cout <a [I] <'';
While (cin> n)
{
Int I = 0, head = 1, tail = size;
While (a [tail]> n) tail --;
While (head <= tail)
{
Int p = a [tail];
While (p * a [head] <= n) p * = a [head ++];
Tail --; I ++;
}
Cout <I <endl;
}
Return 0;
}
# Include <cstdio>
# Include <cstring>
# Include <algorithm>
# Include <functional>
# Include <iostream>
# Include <cstdlib>
# Include <cmath>
Using namespace std;
# Define MAXN (10000)
# Define eps (1e-9)
# Define For (I, n) for (int I = 1; I <= n; I ++)
# Define ForD (I, n) for (int I = n; I --)
# Define Fork (I, k, n) for (int I = k; I <= n; I ++)
Int n, a [MAXN], size = 0;
Bool B [MAXN];
Int main ()
{
Memset (B, 0, sizeof (B); B [1] = 1;
Fork (I, 2, MAXN)
{
If (! B [I]) B [I] = 1, a [++ size] = I;
For (j, size)
{
If (I * a [j]> MAXN) break;
B [I * a [j] = 1;
If (! I % a [j]) break;
}
}
// For (I, 100) cout <a [I] <'';
While (cin> n)
{
Int I = 0, head = 1, tail = size;
While (a [tail]> n) tail --;
While (head <= tail)
{
Int p = a [tail];
While (p * a [head] <= n) p * = a [head ++];
Tail --; I ++;
}
Cout <I <endl;
}
Return 0;
}