题意:

  求1-n内互质数对个数

SOL:

  裸欧拉函数,还有莫比乌斯反演的加速什么的,挖个坑.

Code:

  

/*==========================================================================
# Last modified: 2016-03-16 20:57
# Filename: 2190.cpp
# Description:
==========================================================================*/
#define me AcrossTheSky
#include <cstdio>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> #include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector> #define lowbit(x) (x)&(-x)
#define FOR(i,a,b) for((i)=(a);(i)<=(b);(i)++)
#define FORP(i,a,b) for(int i=(a);i<=(b);i++)
#define FORM(i,a,b) for(int i=(a);i>=(b);i--)
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
#define getlc(a) ch[(a)][0]
#define getrc(a) ch[(a)][1] #define maxn 100000
#define maxm 100000
#define pi 3.1415926535898
#define _e 2.718281828459
#define INF 1070000000
using namespace std;
typedef long long ll;
typedef unsigned long long ull; template<class T> inline
void read(T& num) {
bool start=false,neg=false;
char c;
num=0;
while((c=getchar())!=EOF) {
if(c=='-') start=neg=true;
else if(c>='0' && c<='9') {
start=true;
num=num*10+c-'0';
} else if(start) break;
}
if(neg) num=-num;
}
/*==================split line==================*/
ll ans=3;
int n,p[maxn],pri[maxn],ma[maxn]; void prepare(){
memset(pri,false,sizeof(pri));
for (int i=2;i*i<=n;i++)
if (!pri[i])
for (int j=i*i;j<=n;j+=i)
pri[j]=true,ma[j]=max(ma[j],i);
FORP(i,2,n)
if (!pri[i]) p[i]=i-1;
else if (i/ma[i]%ma[i]==0) p[i]=p[i/ma[i]]*ma[i];
else p[i]=p[i/ma[i]]*(ma[i]-1);
} int main(){
read(n); n--;
prepare();
FORP(i,1,n) ans+=p[i]*2;
printf("%lld",ans);
}

BZOJ2190 & 欧拉函数的更多相关文章

  1. [BZOJ2190&BZOJ2705]欧拉函数应用两例

    欧拉函数phi[n]是表示1~n中与n互质的数个数. 可以用公式phi[n]=n*(1-1/p1)*(1-1/p2)*(1-1/p3)...*(1-1/pk)来表示.(p为n的质因子) 求phi[p] ...

  2. 【bzoj2190】: [SDOI2008]仪仗队 数论-欧拉函数

    [bzoj2190]: [SDOI2008]仪仗队 在第i行当且仅当gcd(i,j)=1 可以被看到 欧拉函数求和 没了 /* http://www.cnblogs.com/karl07/ */ #i ...

  3. BZOJ-2190 仪仗队 数论+欧拉函数(线性筛)

    今天zky学长讲数论,上午水,舒爽的不行..后来下午直接while(true){懵逼:}死循全程懵逼....(可怕)Thinking Bear. 2190: [SDOI2008]仪仗队 Time Li ...

  4. BZOJ2190 [SDOI2008]仪仗队(欧拉函数)

    与HDU2841大同小异. 设左下角的点为(1,1),如果(1,1)->(x,y)和(1,1)->(x',y')向量平行,那只有在前面的能被看见.然后就是求x-1.y-1不互质的数对个数. ...

  5. Bzoj-2190 仪仗队 欧拉函数

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2190 简单的欧拉函数题,实际上就是求gcd(x,y)=1, 0<=x,y<=n ...

  6. BZOJ2190 [SDOI2008]仪仗队 [欧拉函数]

    题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...

  7. 【bzoj2190】[SDOI2008]仪仗队 欧拉函数

    题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图 ...

  8. 【bzoj2190】[SDOI2008]仪仗队 数论 欧拉函数 筛法

    http://www.lydsy.com/JudgeOnline/problem.php?id=2190   裸欧拉函数,先不计算对角线(a,a)的一列,然后算出1到n-1的所有欧拉函数相加*2,再加 ...

  9. 【bzoj2190】【仪仗队】欧拉函数+线性筛(浅尝ACM-J)

    向大(hei)佬(e)势力学(di)习(tou) Description 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪 ...

随机推荐

  1. mySQL中如何给某一IP段的用户授权?

    给一个用用户use ip: 192.168.0.1 语句是: grant all on *.* to root@192.168.0.1 identified by 'pass' 来授权 其中:root ...

  2. execl一个工作薄中有几个个工作表,将这几个个工作表分别保存到不同execl文件中

    用宏运行: Sub QEJebel()    Dim sh As Worksheet    Dim Pa As String    Pa = ThisWorkbook.Path    For Each ...

  3. 以 MAMP 为 Mac OS X 安装并设置 PHP开发环境

    PHP 页需要通过 Web 服务器处理.因此,要在 Dreamweaver 中使用 PHP 进行开发,您需要访问支持 PHP 的 Web 服务器和 MySQL 数据库.phpMyAdmin 也很实用, ...

  4. Linux(CentOS)常用操作指令(一)

    基本指令集合 1.查看CentOS版本信息 cat /proc/version cat /etc/redhat-release 2.查看安全日志文件信息 tail -f /var/log/secure ...

  5. [Unity3d插件]EasyTouch的初步使用

    对于移动平台上的RPG类的游戏,我们常用虚拟摇杆来控制人物角色的行走和一些行为,相信我们对它并不陌生,之前尝试了EasyTouch2.5,发现并没有最新版的3.1好用,2.5版本的对于自适应没有做的很 ...

  6. 在Asp.Net MVC中设定site路径所对应的默认action

    设置路由的default的Controller和Action可以达到我们预期的效果,代码如下所示: public class RouteConfig { public static void Regi ...

  7. merge布局

    当LayoutInflater遇到这个标签时,它会跳过它,并将<merge />内的元素添加到<merge />的父元素里.迷惑了吗?让我们用<merge />来替 ...

  8. Understanding Kafka Consumer Groups and Consumer Lag

    In this post, we will dive into the consumer side of this application ecosystem, which means looking ...

  9. 【java 断点续传】

    模拟 断点续传 首先,先读取word文件的 一部分 package com.sxd.readLines; import java.io.File; import java.io.FileInputSt ...

  10. Java Math floor round ceil 函数

    public final class Math extends Object public static double floor(double a) public static long round ...