Nyoj-471-a lot of trees

Source: Internet
Author: User

A lot of trees.
Time limit: 3000 ms | Memory Limit: 65535 KB
Difficulty: 5

Describe

In that faraway place there is a magical forest, its magic is: the forest in each tree is a pair of integers to determine the coordinates. There is a little red people standing in (0,0) position, look around, see a lot of trees, in front of so many trees, so that it has been countless. Then write a program to help it count.

Input
The first line, an integer n, represents the number of test data sets.
Next there are N (n<=20) rows, with two integers per line i,j (X,y) (0

#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <

Vector> using namespace std;
const int MAXN = 100000 + 5;
BOOL ISUSED[MAXN];

Vector<int> PRIME[MAXN];
void init ()//Gets the mass factor of each number.
    {memset (isused, False, sizeof (isused));
    for (int i = 0; i < MAXN i++) {prime[i].clear (); for (int i = 2; i < MAXN i++) {if (!isused[i)) {prime[i].push_back (i);//If this number is prime then it itself is his
                Decomposition for (int j = I+i J < Maxn j = i) {prime[j].push_back (i);//j represents this number, I represents decomposition
            ISUSED[J] = true;
    Long Long dfs (int row, int x, int col) {Long long ret = 0;
    for (int i = col i < prime[row].size (); i++) {ret = x/prime[row][i]-dfs (row, x/prime[row][i), i+1);
return ret;
int main () {init ();//for (int i = 2; I <= i++) {//printf ("I->%d:", i); for (intj = 0; J < Prime[i].size ();
J + +) {//printf ("%d", prime[i][j]);//}//printf ("\ n");
    int T, x, y;
    CIN >> T;
        while (t--) {cin >> x >> y;
        if (x < y) {int z = x; x = y; y = z;
        Long long treecnt = x;
        for (int i = 2; I <= y; i++) {treecnt = X-dfs (i, x, 0);
    } cout << treecnt << Endl;
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.