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