题目:找到整数区间[1。n]中全部的互质数对。

分析:数论,筛法,欧拉函数。在筛素数的的同一时候。直接更新每一个数字的欧拉函数。

每一个数字一定会被他前面的每一个素数筛到。而欧拉函数的计算是n*π(1-1/pi);

当中,pi是n的素数因子,所以能够利用筛法来计算欧拉函数,然后求和;

注意,这时求出的欧拉函数为全部小于n的数m与n的互质对,所以要乘以2;

(1,1)仅仅有一个,所以还要减掉1。

说明:打表计算,查询输出。

#include <iostream>
#include <cstdlib> using namespace std; int euler[50001];
int sums[50001];
int used[50001]; int main()
{
for (int i = 0 ; i < 50001 ; ++ i) {
used[i] = 0;
euler[i] = i;
} for (int i = 2 ; i < 50001 ; ++ i)
if (!used[i]) {
for (int j = i ; j < 50001 ; j += i) {
used[j] = 1;
euler[j] = euler[j]/i*(i-1);
}
} sums[0] = 0;
for (int i = 1 ; i < 50001 ; ++ i)
sums[i] = sums[i-1]+euler[i]; int n;
while (cin >> n && n)
cout << 2*sums[n]-1 << endl; return 0;
}

UVa 10820 - Send a Table的更多相关文章

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

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

  2. 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 ...

  3. UVa 10820 - Send a Table(欧拉函数)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. Uva 10820 Send a Table(欧拉函数)

    对每个n,答案就是(phi[2]+phi[3]+...+phi[n])*2+1,简单的欧拉函数应用. #include<iostream> #include<cstdio> # ...

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

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

  6. uva 10820 (筛法构造欧拉函数)

    send a table When participating in programming contests, you sometimes face the following problem: Y ...

  7. 【UVA 10820】Send a Table(欧拉函数)

    Description When participating in programming contests, you sometimes face the following problem: Yo ...

  8. UVa 10820 (打表、欧拉函数) Send a Table

    题意: 题目背景略去,将这道题很容易转化为,给出n求,n以内的有序数对(x, y)互素的对数. 分析: 问题还可以继续转化. 根据对称性,我们可以假设x<y,当x=y时,满足条件的只有(1, 1 ...

  9. Uva 10820 交表

    题目链接:https://uva.onlinejudge.org/external/108/10820.pdf 题意: 对于两个整数 x,y,输出一个函数f(x,y),有个选手想交表,但是,表太大,需 ...

随机推荐

  1. opencv+vs2012环境搭建教程

    1. 安装OpenCV和VS. 本人电脑安装的是opencv2.4.10和vs2012 2.配置环境变量 以下以win8 64位系统为例: 计算机->属性->高级系统设置->环境变量 ...

  2. redis学习之一 - linux下安装配置

    Content 0.序 1.如何安装? 2.配置参数及其意义 3.设为linux服务 0.序 本文主要是记录Redis在 Centos下的安装配置 .文中如无特别说明.表示redis-3.2.10代码 ...

  3. Lucene——索引的创建、删除、修改

    package cn.tz.lucene; import java.io.File; import java.util.ArrayList; import java.util.List; import ...

  4. javascript小记-作用域

    一.全局作用域 全局作用域的变量不论在什么时候都可以直接引用,而不必通过全局对象:满足以下条件的变量属于全局作用域:1.在最外层定义的变量2.全局对象的属性3.任何地方隐式定义的变量(未定义直接赋值的 ...

  5. How To Allow Blocked Content on Internet Explorer

    Follow the steps below if you are tired of having to "Enable Blocked Content" in IE each t ...

  6. 达芬奇TI DVSDK之视频数据流过程分析

    作者:openwince@gmail.com 博客:http://www.cnblogs.com/tinz    本文的copyright归openwince@gmail.com所有,使用GPL发布, ...

  7. Save a 32-bit Bitmap as 1-bit .bmp file in C#

    What is the easiest way to convert and save a 32-bit Bitmap to a 1-bit (black/white) .bmp file in C# ...

  8. Eclipse配置mybatis-generator插件的2种方法

    原文:https://blog.csdn.net/u012825737/article/details/79117540 最近在做一个Mybatis的项目,学习到了一个插件mybatis-genera ...

  9. SQL:(转)数据库中的锁机制(数据库中有哪些锁)

    数据库中的锁机制 锁是网络数据库中的一个非常重要的概念,它主要用于多用户环境下保证数据库完整性和一致性.各种大型数 据库所采用的锁的基本理论是一致的,但在具体实现上各有差别.目前,大多数数据库管理系统 ...

  10. Round #169 (Div. 2)C. Little Girl and Maximum Sum

    1.用退化的线段树(也就是没有区间查询)做... 2.注意longlong. #include<cstdio> #include<cstring> #include<io ...