• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            coreBugZJ

            此 blog 已棄。

            POJ 3090. Visible Lattice Points

            Visible Lattice Points
            Time Limit: 1000MS Memory Limit: 65536K
            Total Submissions: 4099 Accepted: 2288

            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

            Source

            Greater New York 2006



             1/*
             2POJ 3090 Visible Lattice Points
             3
             4Farey 數列,歐拉函數。
             5*/

             6
             7
             8#include <stdio.h>
             9#include <string.h>
            10
            11#define  N  1003
            12
            13int prime[ N ], nprime;
            14int fun[ N ], ans[ N ];
            15
            16void init_prime() {
            17        int i, j;
            18        memset( prime, 0sizeof(prime) );
            19        nprime = 0;
            20        for ( i = 2; i < N; ++i ) {
            21                if ( 0 == prime[ i ] ) {
            22                        prime[ nprime++ ] = i;
            23                        for ( j = i+i; j < N; j+=i ) {
            24                                prime[ j ] = 1;
            25                        }

            26                }

            27        }

            28}

            29
            30void init_fun() {
            31        int  i, j;
            32        int t;
            33        for ( i = 1; i < N; ++i ) {
            34                t = i;
            35                for ( j = 0; (j < nprime)&&(prime[j]<=i); ++j ) {
            36                        if ( i % prime[j] == 0 ) {
            37                                t = t * (prime[ j ] - 1/ prime[ j ];
            38                        }

            39                }

            40                fun[ i ] = t;
            41        }

            42        fun[ 1 ] = 0;
            43}

            44
            45void init_ans() {
            46        int i;
            47        ans[ 1 ] = 0;
            48        for ( i = 2; i < N; ++i ) {
            49                ans[ i ] = ans[ i - 1 ] + fun[ i ];
            50        }

            51        for ( i = 1; i < N; ++i ) {
            52                ans[ i ] = ans[ i ] * 2 + 3;
            53        }

            54}

            55
            56int main() {
            57        int n, c, i;
            58        init_prime();
            59        init_fun();
            60        init_ans();
            61
            62        scanf( "%d"&c );
            63        for ( i = 1; i <= c; ++i ) {
            64                scanf( "%d"&n );
            65                printf( "%d %d %d\n", i, n, ans[n] );
            66        }

            67        return 0;
            68}

            69

            posted on 2012-02-29 21:16 coreBugZJ 閱讀(437) 評論(0)  編輯 收藏 引用 所屬分類: ACMAlgorithmMathematics

            亚洲国产精品无码久久久蜜芽| 日本人妻丰满熟妇久久久久久| 波多野结衣中文字幕久久| 青青青国产成人久久111网站| 久久亚洲欧洲国产综合| 国产精品无码久久久久久| 国产成人综合久久综合| 热久久视久久精品18| 久久久久黑人强伦姧人妻| 久久91精品国产91久久小草| 亚洲色大成网站WWW久久九九| 无码8090精品久久一区| 国内精品久久久久久久久电影网 | 久久一日本道色综合久久| 久久综合丁香激情久久| 亚洲伊人久久成综合人影院 | 久久久无码精品亚洲日韩蜜臀浪潮| 久久国产成人午夜aⅴ影院| 久久精品人人做人人爽电影| 老司机午夜网站国内精品久久久久久久久| 午夜精品久久久久久影视riav| 99久久精品国产高清一区二区 | 久久青青草原精品国产不卡| 色88久久久久高潮综合影院| 久久久久久极精品久久久| 99久久久国产精品免费无卡顿| 色青青草原桃花久久综合| 欧美日韩精品久久久免费观看| 久久99热狠狠色精品一区| 亚洲精品乱码久久久久久| 亚洲国产婷婷香蕉久久久久久| 久久青草国产精品一区| 久久亚洲中文字幕精品有坂深雪| 无码人妻久久一区二区三区蜜桃| 久久久久亚洲av综合波多野结衣| 国产福利电影一区二区三区,免费久久久久久久精| 国产精品青草久久久久婷婷| 无码AV中文字幕久久专区| 99久久精品国产一区二区| 中文字幕久久精品无码| 亚洲午夜久久久久妓女影院|