Woj problem 1420-Visible point

Source: Internet
Author: User
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&LT;=T&LT;=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--;
}
}

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.