zoukankan      html  css  js  c++  java
  • POJ3090 Visible Lattice Points 欧拉函数

    欧拉函数裸题,直接欧拉函数值乘二加一就行了。具体证明略,反正很简单。

    题干:

    Description

    A lattice point (x, y) 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 (x, y) 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 (x, y) with 0 ≤ x, y ≤ 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 (x, y) with 0 ≤ x, yN.

    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<iostream>
    #include<cstdio>
    #include<cmath>
    #include<ctime>
    #include<queue>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    #define duke(i,a,n) for(int i = a;i <= n;i++)
    #define lv(i,a,n) for(int i = a;i >= n;i--)
    #define clean(a) memset(a,0,sizeof(a))
    const int INF = 1 << 30;
    typedef long long ll;
    typedef double db;
    template <class T>
    void read(T &x)
    {
        char c;
        bool op = 0;
        while(c = getchar(), c < '0' || c > '9')
            if(c == '-') op = 1;
        x = c - '0';
        while(c = getchar(), c >= '0' && c <= '9')
            x = x * 10 + c - '0';
        if(op) x = -x;
    }
    template <class T>
    void write(T x)
    {
        if(x < 0) putchar('-'), x = -x;
        if(x >= 10) write(x / 10);
        putchar('0' + x % 10);
    }
    int phi[1000005],n;
    void init(int n)
    {
        phi[1] = 1;
        duke(i,2,n)
        {
            phi[i] = i;
        }
        duke(i,2,n)
        {
            if(phi[i] == i)
            {
                for(int j = i;j <= n;j += i)
                {
                    phi[j] = phi[j] / i * (i - 1);
                }
            }
        }
        duke(i,2,n)
        {
            phi[i] = phi[i - 1] + phi[i];
        }
    }
    int dp[10004],maxn = 0;
    int main()
    {
        read(n);
        duke(i,1,n)
        {
            read(dp[i]);
            maxn = max(maxn,dp[i]);
        }
        init(maxn);
        duke(i,1,n)
        {
            printf("%d %d %d
    ",i,dp[i],phi[dp[i]] * 2 + 1);
        }
        return 0; 
    }
    代码:

  • 相关阅读:
    flask简单应用以及配置文件的写法。
    Django REST framework使用及源码分析之节流
    rancher1.6高可用集群搭建
    Rancher安装多节点高可用(HA)
    Rancher 2.2.2
    TeamCity+Rancher+Docker实现.Net Core项目DevOps(目前成本最小的DevOps实践)
    Docker学习笔记_10 docker应用
    一键获取数据库整体信息脚本
    MySQL性能优化最佳实践
    MySQL性能优化最佳实践
  • 原文地址:https://www.cnblogs.com/DukeLv/p/9775215.html
Copyright © 2011-2022 走看看