Problem 1420-Visible point
Time Limit: 3000MS
Memory Limit: 65536KB
Difficulty: 3
Total Submit: 539
Accepted: 113
Special Judge: No Description plane has m*n on the whole point, their coordinates (x, y) meet 1<=x<=m, 1<=y<=n, x, y are integers. The number of points that can be seen from the origin (if there is no other point on the line to the origin, the point can be seen by the origin).
Input first line a number T (1<=T<=15), which represents the number of groups of data
One row per group of data, two digits per line m,n (0<=m, n<=50000)
Output for each set of data, the total number of points that can be seen by the origin.
Sample Input 2
1 1
2 3
Sample Output 1
5
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
using namespace Std;
int n,m;
int Ans;
Vector<int> F;
void Dfs (int step,int frac,int Tot)
{
if (Step >= f.size ())
{
if (tot&1)
Ans-= (Long Long) (M/FRAC);
Else
Ans + = (long Long) (M/FRAC);
Return
}
Dfs (step+1,frac*f[step],tot+1);
Dfs (Step+1,frac,tot);
}
void Count (int Num)
{
int Cur = Num;
F.clear ();
for (int i=2;i*i<=num;i++)
if (cur%i = = 0)
{
F.push_back (i);
while (cur%i = = 0)
Cur/= i;
}
if (Cur > 1) f.push_back (Cur);
Dfs (0,1,0);
}
int main ()
{
int n;
CIN >> N;
while (n>0)
{
Ans = 0;
CIN >>M>>N;
for (int i=1;i<=n;i++)
Count (i);
cout<<ans<< ' \ n ';
N--;
}
}