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 ...
随机推荐
- fiddler 插件开发
本文主要讲解使用.net C#语言开发Fiddler插件. 1.在Fiddler 会话列表中添加自定义列 使用FiddlerApplication.UI.lvSessions.AddBoundColu ...
- Java将整个文件夹里的文本中的字符串替换成另外一个字符串(可用于项目复制,变成另一个项目)
import org.junit.Test; import java.io.*; /** * User: HYY * Date: 13-8-18 * Time: 下午8:11 * To change ...
- SQL四种语言:DDL,DML,DCL,TCL
1.DDL(Data Definition Language)数据库定义语言statements are used to define the database structure or schema ...
- highcharts 切换
<!doctype html> <html lang="en"> <head> <script type="text/javas ...
- C++常用语法
unordered_map<int, Node*> mp; if (mp.find(key) == mp.end()) unordered_map<int, Node*>::i ...
- IOS开发基础
http://blog.csdn.net/wokenshin/article/details/50292253 1.修改UI大小 2.设置颜色 3.禁止横屏 4.点击空白处隐藏键盘 5.弹出键盘时,后 ...
- C#基础精华07(委托事件,委托的使用,匿名方法)
1.委托概述 委托是一种数据类型,像类一样(可以声明委托类型变量).方法参数可以是int.string.类类型 void M1(int n){ } √ void M2(string s){ } √ ...
- 92. Reverse Linked List II
题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1- ...
- [原]数据库中的partitioning和sharding
1. 如何理解定义 在中文中,partitioning和sharding都有分区的意思.从大的方面来说,这两个词所执行的动作确实也和分区相关.partitioning在很多场合是vertical pa ...
- forks rate异常
一.收到nagios Current_load报警短信