首页 > 其他分享 >POJ 3090 Visible Lattice Points

POJ 3090 Visible Lattice Points

时间:2022-11-09 19:41:08浏览次数:48  
标签:phi const visible int Visible 3090 Points include define


Description



A lattice point (xy) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (xy) does not pass through any other lattice point. For example, the point (4, 2) is not visible since the line from the origin passes through (2, 1). The figure below shows the points (xy) with 0 ≤ xy ≤ 5 with lines from the origin to the visible points.




Write a program which, given a value for the size, N, computes the number of visible points (xy) with 0 ≤ xy ≤ N.


Input



The first line of input contains a single integer C (1 ≤ C ≤ 1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing a single integer N (1 ≤ N ≤ 1000), which is the size.


Output



For each dataset, there is to be one line of output consisting of: the dataset number starting at 1, a single space, the size, a single space and the number of visible points for that size.


Sample Input



4 2 4 5 231


Sample Output



1 2 5 2 4 13 3 5 21

4 231 32549


其实就是求欧拉函数,数据小暴力求也行。

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define pii pair<int,LL>
#define in(x) scanf("%d", &x);
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-4;
const int INF = 0x7FFFFFFF;
const int mod = 998244353;
const int N = 1e6 + 10;
int n, sum[N];
int phi[N], f[N], p[N], t, T;

void init()
{
t = 0; sum[1] = phi[1] = f[1] = 1;
rep(i, 2, N - 1)
{
if (!f[i]) p[t++] = i, phi[i] = i - 1;
for (int j = 0,k; j < t&&p[j] * i < N; j++)
{
k = p[j] * i; f[k] = 1;
phi[k] = phi[i] * (p[j] - 1);
if (i % p[j] == 0) { phi[k] = phi[i] * p[j]; break; }
}
sum[i] = sum[i - 1] + phi[i] * 2;
}
}

int main()
{
init(); in(T);
int cas = 0;
while (T--)
{
scanf("%d", &n);
printf("%d %d %d\n", ++cas, n, sum[n] + 2);
}
return 0;
}



标签:phi,const,visible,int,Visible,3090,Points,include,define
From: https://blog.51cto.com/u_15870896/5838597

相关文章

  • Codeforces Global Round 16 F | CF1566F Points Movement
    https://www.luogu.com.cn/problem/CF1566Fhttps://codeforces.com/contest/1566/problem/F这类有关线段的问题我通常都是先观察线段的包含/交对线段是否保留的影响,以约......
  • PyTorch笔记:如何保存与加载checkpoints
    https://pytorch.org/tutorials/recipes/recipes/saving_and_loading_a_general_checkpoint.html保存和加载checkpoints很有帮助。为了保存checkpoints,必须将它们放在......
  • Divide Points
    传送门Sol1神奇的构造。。思路自然直接:枚举\(Dist\),对所有\(dist(i,j)=Dist\)的点对连接\(i,j\),然后剔除所有度数为\(0\)的点,这样就建立了一张图。然后跑dfs判......
  • charles中Map、Rewrite、Breakpoints的区别
    Charles提供了Map功能、Rewrite功能、Breakpoints功能,都可以达到修改服务器返回内容的目的,这三者的差异是:MapMap功能适合长期的将某些请求重定向到另一个网络地址或本地......
  • Nearest Excluded Points ( 转化思想 +多源BFS )
     思路:思路暴力枚举每一个点,暴力做时间会超观察发现:每一个所找的空白点,一定是紧紧挨着红色的点, 于是把这些空白点入队,然后利用bfs,即可搞出来空间用ma......
  • Codeforces - 1744E2 - Divisible Numbers (hard version)(数论 + 暴力 + 思维 、 *190
    1744E2-DivisibleNumbers(hardversion)(⇔源地址)目录1744E2-DivisibleNumbers(hardversion)(⇔源地址)tag题意思路正解后日谈AC代码错误次数:2本......
  • RabbitMQ.Client.Exceptions.BrokerUnreachableException:“None of the specified en
    RabbitMQ和程序运行在同一台电脑上可以使用guest账号访问如果不在同一台电脑,就会报错RabbitMQ.Client.Exceptions.BrokerUnreachableException:“Noneofthespecified......
  • CF1311F Moving Points
    题目传送门思路给出一种不需要脑子的四颗树状数组解法。这四颗树状数组分别为:一颗维护负数,一颗维护负数个数,一颗维护正数,一颗维护正数个数。首先考虑没有速度该怎么求......
  • 【luogu CF1140F】Extending Set of Points(线段树分治)
    ExtendingSetofPoints题目链接:luoguCF1140F题目大意有一个点集,有一个扩展操作是加入符合条件的(x0,y0)直到不能加入位置。符合条件是原来(x0,y0)不存在而且存......
  • E2. Divisible Numbers (hard version)
    E2.DivisibleNumbers(hardversion)Thisisanhardversionoftheproblem.Theonlydifferencebetweenaneasyandahardversionistheconstraintson$a,b......