E - (例题)欧拉函数求和

Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Submit Status

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
题目大意:给你一个n*n的网格,任意一点和(0,0)连线,可以组成一条直线,前面的点可以挡住后面的点,问你能看到的点到底有多少个
思路分析:题目实际上就是问在这个网格上有多少种不同的斜率,边上的两点我们先不管,然后将整个正方形分成上三角和下三角两部分,
由对称性,两边可以看到的点的数目肯定一样多,以下三角为例进行研究,我们会发现,对于所有能看到的点,他们有着一个共同的特征,
那就是gcd(x,y)=1,若不为1,则他前面肯定有一个点挡住了这个点,那么本题就转变成了一个求欧拉函数和的简单题目,注意不要将分界线
上的点加,记t=phi[1]+phi[2]+.......+phi[n],则ans=(t-1)*2+1+2=2*t+1
代码:
#include<iostream>
#include<cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn=;
int prime[maxn];
int phi[maxn];
bool check[maxn];
int tot;
void make_prime()
{
phi[]=;
memset(check,true,sizeof(check));
tot=;
for(int i=;i<=maxn;i++)
{
if(check[i])
{
prime[tot++]=i;
phi[i]=i-;
}
for(int j=;j<tot&&i*prime[j]<=maxn;j++)
{
check[i*prime[j]]=false;
if(i%prime[j]==)
{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
else phi[i*prime[j]]=phi[i]*(prime[j]-);
}
}
}
int kase;
int main()
{
int T;
make_prime();
scanf("%d",&T);
kase=;
ll num;
while(T--)
{
int n;
scanf("%d",&n);
ll ans=;
for(int i=;i<=n;i++)
{
ans+=phi[i];
}
printf("%d %d %lld\n",++kase,n,ans*+);
}
}

poj3090欧拉函数求和的更多相关文章

  1. 【BZOJ4805】欧拉函数求和(杜教筛)

    [BZOJ4805]欧拉函数求和(杜教筛) 题面 BZOJ 题解 好久没写过了 正好看见了顺手切一下 令\[S(n)=\sum_{i=1}^n\varphi(i)\] 设存在的某个积性函数\(g(x) ...

  2. BZOJ4805: 欧拉函数求和(杜教筛)

    4805: 欧拉函数求和 Time Limit: 15 Sec  Memory Limit: 256 MBSubmit: 614  Solved: 342[Submit][Status][Discus ...

  3. HDU2824-The Euler function-筛选法求欧拉函数+求和

    欧拉函数: φ(n)=n*(1-1/p1)(1-1/p2)....(1-1/pk),其中p1.p2-pk为n的所有素因子.比如:φ(12)=12*(1-1/2)(1-1/3)=4.可以用类似求素数的筛 ...

  4. [BZOJ]4805: 欧拉函数求和

    解题思路类似莫比乌斯函数之和 题目大意:求[1,n]内的欧拉函数$\varphi$之和.($n<=2*10^{9}$) 思路:令$ M(n)=\sum_{i=1}^{n}\varphi (i)  ...

  5. 【bzoj3944/bzoj4805】Sum/欧拉函数求和 杜教筛

    bzoj3944 题目描述 输入 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 输出 一共T行,每行两个用空格分隔的数ans1,ans2 样例输 ...

  6. BZOJ 4805: 欧拉函数求和 杜教筛

    https://www.lydsy.com/JudgeOnline/problem.php?id=4805 给出一个数字N,求sigma(phi(i)),1<=i<=N https://b ...

  7. 【BZOJ3944/4805】Sum/欧拉函数求和 杜教筛

    [BZOJ3944]Sum Description Input 一共T+1行 第1行为数据组数T(T<=10) 第2~T+1行每行一个非负整数N,代表一组询问 Output 一共T行,每行两个用 ...

  8. Note -「因数的欧拉函数求和」

    归档. 试证明:\(\sum \limits _{d | x} \varphi (d) = x\) Lemma 1. 试证明:\(\sum \limits _{d | p^k} \varphi (d) ...

  9. Bzoj4805: 欧拉函数求和

    好久没写杜教筛了 练练手AC量刷起 # include <bits/stdc++.h> # define RG register # define IL inline # define F ...

随机推荐

  1. Centos6.5使用yum安装Mysql5.7

    想要玩新的东东就要付出代价,我的时间悄悄的都溜走了,说多了都是泪! 实践才是真理! 系统版本:Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 ...

  2. Fedora22没有i18n文件

    今天想修改Fedora22的系统语言,发现/etc/sysconfig/没有i18n 解决方法: dnf install system-config-language.noarch -y system ...

  3. 如何使用JSONP

    1.使用$.getJSON() $.getJSON(" http://跨域的dns/document!searchJSONResult.action?name1="+value1+ ...

  4. QQ联系客服

    $('.side').bind('mouseenter mouseleave',function(e){ if(e.type=="mouseenter"){ if(!$(this) ...

  5. Python中unittest采用不同的参数组合产生独立的test case

    我们在使用Python的unittest做自动化或者单元测试时,有时需要一个测试用例根据不同的输入.输出组合而执行多次,但是,unittest中一个用例只能有一组参数组合执行,如果采用循环的方式,在生 ...

  6. 磁珠(FB)的选用

    1. 磁珠(FB)的单位是欧姆,而不是亨特,这一点要特别注意.因为磁珠的单位是按照它在某一频率 产生的阻抗来标称的,阻抗的单位也是欧姆.磁珠的 DATASHEET上一般会提供频率和阻抗的特性曲线图,一 ...

  7. 关于group by

    <pre name="code" class="sql">关于group by 排序问题 10g 以前sort group by 需要排序 10g ...

  8. 【绿茶书情】:《SOHO小报》和《凤… - 绿茶的日志 - 网易博客

    [绿茶书情]:<SOHO小报>和<凤- - 绿茶的日志 - 网易博客 [绿茶书情]:<SOHO小报>和<凤-  

  9. jQuery 遍历 json 方法大全

    1.for循环: var obj = { "status":1, "bkmsg":"\u6210\u529f", "bkdata& ...

  10. 关于ionic传值

    今天,也是偶然发现有的初学者对ionic的传值还不太清除,这里我说明一下 例如你想在这个页面传递参数a.b过去,传递到"tab.wait"页面 $state.go("ta ...