Bzoj-2190 仪仗队 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2190
简单的欧拉函数题,实际上就是求gcd(x,y)=1, 0<=x,y<=n的对数。。
//STATUS:C++_AC_24MS_1584KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int phi[N],prime[N];
int cnt; void phitable(int n)
{
int i,j;
cnt=;phi[]=;
for(i=;i<=n;i++){
if(!phi[i]){
prime[cnt++]=i;
phi[i]=i-;
}
for(j=;j<cnt && i*prime[j]<=n;j++){
if(i%prime[j]){
phi[i*prime[j]]=phi[i]*(prime[j]-);
}else {phi[i*prime[j]]=phi[i]*prime[j];break;}
}
}
} int n; int main(){
// freopen("in.txt","r",stdin);
int i,j,ans=;
scanf("%d",&n);
phitable(n);
for(i=;i<n;i++)ans+=phi[i];
printf("%d\n",ans<<|); return ;
}
Bzoj-2190 仪仗队 欧拉函数的更多相关文章
- BZOJ2190 [SDOI2008]仪仗队 [欧拉函数]
题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...
- P2158 [SDOI2008]仪仗队 && 欧拉函数
P2158 [SDOI2008]仪仗队 题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线 ...
- 【bzoj2190】[SDOI2008]仪仗队 欧拉函数
题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...
- P2158 [SDOI2008]仪仗队 欧拉函数模板
题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- 【P2158】仪仗队&欧拉函数详解
来一道数论题吧. 这个题一眼看上去思路明确,应该是数论,但是推导公式的时候却出了问题,根本看不出来有什么规律.看了马佬题解明白了这么个规律貌似叫做欧拉函数,于是就去百度学习了一下这东西. 欧拉函数的含 ...
- luogu2158 [SDOI2008]仪仗队 欧拉函数
点 $ (i,j) $ 会看不见当有 $ k|i $ 且 $ k|j$ 时. 然后就成了求欧拉函数了. #include <iostream> #include <cstring&g ...
- 洛谷 - P2158 - 仪仗队 - 欧拉函数
https://www.luogu.org/problemnew/show/P2158 好像以前有个妹子收割铲也是欧拉函数. 因为格点直线上的点,dx与dy的gcd相同,画个图就觉得是欧拉函数.但是要 ...
- 洛谷P2158 [SDOI2008]仪仗队 欧拉函数的应用
https://www.luogu.org/problem/P2158 #include<bits/stdc++.h> #define int long long using namesp ...
随机推荐
- jquery类选择器无法取得对象问题原因
<html> <script type="text/javascript" src="jquery-1.9.1.js"></scr ...
- Jetty实践-Hello World
该程序摘自官网教程: 1.首先去Jetty官网,下载jetty-distribution-9.2.6.v20141205.zip,Jetty Jar包,解压到任意目录: 2.使用Eclipse新建一个 ...
- express中ejs模板引擎
1.在 app.js 中通过以下两个语句设置了 引擎类型 和页面模板的位置: app.set('views', __dirname + '/views'); app.set('view engine' ...
- A JSTL primer, Part 2: Getting down to the core
In the initial article of this series, you got your first look at JSTL. We described the use of its ...
- Executing a script from Nagios event handler fails to run
I have Nagios running on a webserver. For this one Nagios service check in particular, if it fails, ...
- HDU 2159 FATE (DP 二维费用背包)
题目链接 题意 : 中文题不详述. 思路 : 二维背包,dp[i][h]表示当前忍耐值为i的情况下,杀了h个怪得到的最大经验值,状态转移方程: dp[i][h] = max(dp[i][h],dp[i ...
- hbase总结:如何监控region的性能
转载:http://ju.outofmemory.cn/entry/50064 随着大数据表格应用的驱动,我们的HBase集群越来越大,然而由于机器.网络以及HBase内部的一些不确定性的bug,使得 ...
- 孟岩的c++ 的学习方法,这何尝有不是做人做事的方法呢?
“(孟岩)我主张,在具备基础之后,学习任何新东西,都要抓住主线,突出重点.对 于关键理论的学习,要集中精力,速战速决.而旁枝末节和非本质性的知识内容,完全可 以留给实践去零敲碎打. “原因是这样的,任 ...
- Vim插件列表
01.helm(Vim-Swoop) 02.ap/vim-buftabline 03.wesleyche/SrcExpl 04.vim proc 05.vim shell 06.dhruvasagar ...
- 新建并保存一个空的Excel
测试用的 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...