Principle of hdu2841Visible Trees rejection
// Given an n * m square, the farmer can only see it from (0, 0 ).
// The first grid in a straight line. Ask the farmer to see several grids.
// For any coordinate (x, y), the coordinates on the same line are (k * x, k * y)
// You can enumerate all the x values and find the number of mutual classes in (1, m ).
# Include
# Include
# Include
# Include
Using namespace std;
Typedef _ int64 ll;
Const int maxn = 100010;
Int isp [maxn];
Vector Vec [maxn];
Void set ()
{
Memset (isp, 0, sizeof (isp ));
For (int I = 2; I <maxn; I + = 2)
Vec [I]. push_back (2 );
For (int I = 3; I <maxn; I + = 2)
{
If (isp [I]) continue;
For (int j = I; j <maxn; j + = I)
{
Isp [j] = 1;
Vec [j]. push_back (I );
}
}
}
Int dfs (int pos, int x, int num)
{
Int ans = 0;
For (int I = pos; I <vec [x]. size (); I ++)
Ans + = num/vec [x] [I]-dfs (I + 1, x, num/vec [x] [I]);
Return ans;
}
Int main ()
{
Int n, m;
Set ();
Int T; scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n, & m );
Ll ans = m;
For (int I = 2; I <= n; I ++)
Ans + = (m-dfs (0, I, m ));
Printf ("% I64d \ n", ans );
}
Return 0;
}