Principle of hdu2841Visible Trees rejection

Source: Internet
Author: User

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;
}











Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.