\(\Large\textbf{Description:} \large{输入n,求有多少个二元组(x,y)满足:1\leqslant x,y\leqslant n,且x和y互素。}\)

\(\Large\textbf{Solution:} \large{不难发现除了(1,1)外,其他二元组的x,y都不相等。设满足x < y的二元组有g(n)个,那么答案为2\times g(n) + 1。}\)

\(\large{其中g(n)=\sum_{i=2}^n\Phi(i)}。\)

\(\Large\textbf{Code:}\)

#include <cmath>
#include <cstdio>
#include <algorithm>
#define LL long long
#define gc() getchar()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int N = 5e4 + 5;
int n, cnt, prime[N], phi[N];
LL sum[N];
bool vis[N]; inline int read() {
char ch = gc();
int ans = 0;
while (ch > '9' || ch < '0') ch = gc();
while (ch >= '0' && ch <= '9') ans = (ans << 1) + (ans << 3) + ch - '0', ch = gc();
return ans;
} inline void euler() {
phi[1] = 1;
rep(i, 2, N) {
if (!vis[i]) prime[++cnt] = i, phi[i] = i - 1;
for (int j = 1; j <= cnt && i * prime[j] <= N; ++j) {
vis[prime[j] * i] = true;
if (i % prime[j] == 0) {
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
else phi[i * prime[j]] = phi[i] * (prime[j] - 1);
}
}
} int main() {
euler();
rep(i, 1, N) sum[i] = sum[i - 1] + phi[i];
n = read();
while (n) {
printf("%lld\n", 2 * sum[n] - 1);
n = read();
}
return 0;
}

\(\large\color{pink}{by\quad Miraclys}\)

UVA10820 交表 Send a Table的更多相关文章

  1. UVa10820 Send a Table[欧拉函数]

    Send a TableInput: Standard Input Output: Standard Output When participating in programming contests ...

  2. Berkeley DB的数据存储结构——哈希表(Hash Table)、B树(BTree)、队列(Queue)、记录号(Recno)

    Berkeley DB的数据存储结构 BDB支持四种数据存储结构及相应算法,官方称为访问方法(Access Method),分别是哈希表(Hash Table).B树(BTree).队列(Queue) ...

  3. 聚簇(Cluster)和聚簇表(Cluster Table)

    聚簇(Cluster)和聚簇表(Cluster Table) 时间:2010-03-13 23:12来源:OralanDBA.CN 作者:AlanSawyer 点击:157次 1.创建聚簇 icmad ...

  4. UVA 10820 - Send a Table 数论 (欧拉函数)

    Send a Table Input: Standard Input Output: Standard Output When participating in programming contest ...

  5. UVA 10820 Send a Table euler_phi功能

    除1,1其他外国x,y不等于 为 x<y 案件 一切y有phi(y)组合 F[x]= phi(i) 2<=i<=x 结果为 2*F[x]+1 Problem A Send a Tab ...

  6. MySQL 建表语句 create table 中的列定义

    MySQL 建表语句 create table 中的列定义: column_definition: data_type [NOT NULL | NULL] [DEFAULT default_value ...

  7. 哈希表(Hash Table)原理及其实现

    原理 介绍 哈希表(Hash table,也叫散列表), 是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度.这个映 ...

  8. 表优化 altering table OPTIMIZE TABLE `sta_addr_copy`

    表优化 altering table OPTIMIZE TABLE `sta_addr_copy` [总结] 1.实际测试的结果是,在state sqlaltering table OPTIMIZE ...

  9. Hash表(hash table ,又名散列表)

    直接进去主题好了. 什么是哈希表? 哈希表(Hash table,也叫散列表),是根据key而直接进行访问的数据结构.也就是说,它通过把key映射到表中一个位置来访问记录,以加快查找的速度.这个映射函 ...

随机推荐

  1. Day11 - F - A Dangerous Maze LightOJ - 1027

    求期望注意期望的定义,这题我们可以分正负数情况,设所求期望为E 正数: 1/n*x_i 负数:1/n*(E+x_j) 此时概率为1/n,根据期望定义,他回到起点后出去的期望为E,花费回起点的时间为x_ ...

  2. leetCode练题——20. Valid Parentheses

    1.题目 20. Valid Parentheses——Easy  Given a string containing just the characters '(', ')', '{', '}',  ...

  3. maven设置镜像地址

    方法一:在maven文件夹下的settings.xml中添加(对所有的项目都有效) <mirror> <id>alimaven</id> <name>a ...

  4. 虚拟机下修改ip配置

    // centos ip 配置vim /etc/sysconfig/network-scripts/ifcfg-eth0 // 虚拟机下删除里面的内容vim /etc/udev/rules.d/70- ...

  5. PAT T1014 Circles of Friends

    大水题,dfs判连通块的数量,bfs每个点找朋友圈的最大直径~ #include<bits/stdc++.h> using namespace std; ; vector<int&g ...

  6. Spring学习(五)

    自动装备 1.定义 自动装配(autowiring): 将某个Bean实例中所引用的其它的Bean自动注入到当前Bean实例中 自动装配就是指由Spring来自动地注入依赖对象,无需人工参与. 自动装 ...

  7. Servlet 学习(五)

    重定向redirect 1.使用方法 response.sendRedirect("/应用名/ 访问资源名"); response.sendRedirect(request.get ...

  8. day11 作业

    # 1.编写装饰器,为多个函数加上认证的功能(用户的账号密码来源于文件), # 要求登录成功一次,后续的函数都无需再输入用户名和密码 # FLAG = False # def login(func): ...

  9. Intellij Idea 下包建包,无论怎么建都在同一级,已解决(附图)

    1.很多新手,刚开始使用Intellij Idea的时候,项目建包都出现所建的包都在用一级. 2.这是因为,刚开始建项目的时候,Hide Empty Middle Packages是默认勾选的,只要去 ...

  10. js中各种类型转换为Boolean类型

    数据类型  转换为true的值  转换为false的值 Boolean  true  false String  任何非空字符串  空字符串 Number  任何非零数字值(包括无穷大) 0和null ...