题目:找到整数区间[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. web文件上传组件比较jQuery File Upload和Fine Uploader

    jQuery File Upload: https://blueimp.github.io/jQuery-File-Upload/ Fine Uploader: http://fineuploader ...

  2. Shell 学习笔记之函数

    hello_fun(){ echo "hello world" echo "$1" # 第一个参数,其中第0个参数为文件本身 } hello_fun 1 在函数 ...

  3. ZOJ 3626 Treasure Hunt I 树上DP

    E - Treasure Hunt I Time Limit:2000MS Memory Limit:65536KB Description Akiba is a dangerous country ...

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

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

  5. react父子组件数据传递

    子传父 1.首先父组件设定一个自定义函数 getChildDatas = (values) => { //...业务代码 } 2.将该函数暴露在子组件的引用上 <Child getChil ...

  6. SoC嵌入式软件架构设计之七:嵌入式文件系统设计

    嵌入式的系统区(system disk,SD)包含操作系统.驱动.中间件.应用和字库.UI资源等文件,本文讲述SD区的文件系统设计.文件系统最基本的目标是为了实现单个文件的定位和读写.由于一般代码都是 ...

  7. WINDOWS WPA性能分析

    http://r12f.com/posts/introduction-to-wpa-1-why-it-is-slow/ http://www.freebuf.com/column/138862.htm ...

  8. QT 安装 4.8.7 on solaris 10

    1.  下载 QT 4.8.7: http://download.qt.io/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4 ...

  9. IOS学习笔记41--图片的缩放(一)

    图片的缩放 一:Pinch手势对图片进行缩放.即用两根手指往不同方向拖拉照片,照片会被缩小或放大. 我理解的原理:等比缩放 先看如下关键代码: 1.初始化参数 - (void)viewDidLoad ...

  10. Swift教程之枚举语法

    import Foundation //MARK:-------枚举语法----------- //不像 C 和 Objective-C 一样.Swift 的枚举成员在被创建时不会被赋予一个默认的整数 ...