poj 2478 Farey Sequence 欧拉函数前缀和
Time Limit: 1000MS | Memory Limit: 65536K | |
Description
F2 = {1/2}
F3 = {1/3, 1/2, 2/3}
F4 = {1/4, 1/3, 1/2, 2/3, 3/4}
F5 = {1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5}
You task is to calculate the number of terms in the Farey sequence Fn.
Input
Output
Sample Input
- 2
- 3
- 4
- 5
- 0
Sample Output
- 1
- 3
- 5
- 9
Source
POJ Contest,Author:Mathematica@ZSU
- #include<iostream>
- #include<cstring>
- #include<cstdio>
- using namespace std;
- #define ll long long
- #define esp 1e-13
- const int N=1e3+,M=1e6+,inf=1e9+,mod=;
- ll p[M],ji;
- bool vis[M];
- ll phi[M];
- ll sum[M];
- void get_eular(int n)
- {
- ji = ;
- memset(vis, true, sizeof(vis));
- for(int i = ; i <= n; i++)
- {
- if(vis[i])
- {
- p[ji ++] = i;
- phi[i] = i - ;
- }
- for(int j = ; j < ji && i * p[j] <= n; j++)
- {
- vis[i * p[j]] = false;
- if(i % p[j] == )
- {
- phi[i * p[j]] = phi[i] * p[j];
- break;
- }
- else
- phi[i * p[j]] = phi[i] * phi[p[j]];
- }
- }
- }
- int main()
- {
- int x,i;
- get_eular(M);
- memset(sum,,sizeof(sum));
- for(i=;i<=1e6;i++)
- sum[i]=sum[i-]+phi[i];
- while(~scanf("%d",&x))
- {
- if(!x)break;
- printf("%lld\n",sum[x]);
- }
- return ;
- }
poj 2478 Farey Sequence 欧拉函数前缀和的更多相关文章
- poj 2478 Farey Sequence(欧拉函数是基于寻求筛法素数)
http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2. ...
- hdu1787 GCD Again poj 2478 Farey Sequence 欧拉函数
hdu1787,直接求欧拉函数 #include <iostream> #include <cstdio> using namespace std; int n; int ph ...
- POJ2478 Farey Sequence —— 欧拉函数
题目链接:https://vjudge.net/problem/POJ-2478 Farey Sequence Time Limit: 1000MS Memory Limit: 65536K To ...
- poj2478 Farey Sequence (欧拉函数)
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...
- UVA12995 Farey Sequence [欧拉函数,欧拉筛]
洛谷传送门 Farey Sequence (格式太难调,题面就不放了) 分析: 实际上求分数个数就是个幌子,观察可以得到,所求的就是$\sum^n_{i=2}\phi (i)$,所以直接欧拉筛+前缀和 ...
- poj2478 Farey Sequence 欧拉函数的应用
仔细看看题目,按照题目要求 其实就是 求 小于等于n的 每一个数的 欧拉函数值 的总和,为什么呢,因为要构成 a/b 然后不能约分 所以 gcd(a,b)==1,所以 分母 b的 欧拉函数值 ...
- POJ 2478 Farey Sequence(欧拉函数前n项和)
A - Farey Sequence Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- Farey Sequence (欧拉函数+前缀和)
题目链接:http://poj.org/problem?id=2478 Description The Farey Sequence Fn for any integer n with n >= ...
- Poj 2478-Farey Sequence 欧拉函数,素数,线性筛
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14291 Accepted: 5647 D ...
随机推荐
- Cocos2d-x Lua中多场景切换生命周期
在多个场景切换时候,场景的生命周期会更加复杂.这一节我们介绍一下场景切换生命周期.多个场景切换时候分为几种情况:情况1,使用pushScene函数从实现GameScene场景进入SettingScen ...
- 1714 B君的游戏(Nim博弈)
1714 B君的游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 B君和L君要玩一个游戏.刚开始有n个正整数 ai . 双方轮流操作.每次操作,选一个正整数 ...
- Quartz实现定时功能
---------------------------------博主讲废话 在自己实现爬取某个网站的信息后,发现,如果要自己每次把程序跑一遍不太现实(麻烦),所以有没有什么可以实现 定时的功能,只要 ...
- MySql最左前缀原则
简单整理记录下,之前一直都没有关注过这个问题 最左前缀原则:顾名思义是最左优先,以最左边的为起点任何连续的索引都能匹配上, 注:如果第一个字段是范围查询需要单独建一个索引 注:在创建多列索引时,要根据 ...
- [转载]mvc:view-controller
1.重定向 ? 1 <mvc:view-controller path="/" view-name="redirect:/admin/index"/> ...
- LeetCode-day05
45. Single Number 在个数都为2的数组中找到个数为1的数 46. Missing Number 在数组中找到从0到n缺失的数字 47. Find the Difference 找两个字 ...
- gearman background后台job状态获取
GearmanClient background job有一个方法叫: public array GearmanClient::jobStatus ( string $job_handle ) Get ...
- python基础知识——包
包是一种通过使用“模块名”来组织python模块的名称空间的方式. 无论是import形式还是from...import形式,凡是在导入语句中(不是在使用时)遇到带点的,就需要意识到——这是包. 包是 ...
- Vue:实践学习笔记(3)——组件使用
Vue:实践学习笔记(3)——组件使用 全局注册 1.注册组件 Vue.component('my-component',{ //选项 }) 说明:my-component就是注册的组件自定义的标签名 ...
- rails 增删改查
class InvoicesController < ApplicationController def index @invoices = Invoice.all end def show @ ...