嘟嘟嘟

【欧拉函数】

大致题意:如果知道f(a, b),就可以求出f(a * k, b * k)。现给出一个n,求至少需要知道几个二元组(a, b),使所有的f(x, y)都能求出来。(1 <= x, y <= n)

首先能确定的是gcd(a, b) = 1。不妨假设b >= a,那么如果b一定,至少需要phi(b)个a,才能知道所有的f(a * k, b * k)。令dp[n]表示这种情况下的答案,则dp[n] = ∑phi[i] (1 <= i <= n)。

上述是在a <= b的条件下得出的,如果没有这个条件,那么dp'[n] = dp[n] * 2 - 1。因为对于f(1, 1)只用求一遍。

总结一下,O(nlogn)预处理欧拉函数(当然线性的更好了)和前缀和,然后O(1)询问。

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 5e4 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), las = ' ';
while(!isdigit(ch)) las = ch, ch = getchar();
while(isdigit(ch)) ans = ans * + ch - '', ch = getchar();
if(las == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar(x % + '');
} int n, phi[maxn], sum[maxn]; void euler()
{
for(int i = ; i < maxn; ++i) phi[i] = i;
for(int i = ; i < maxn; ++i) if(phi[i] == i)
for(int j = i; j < maxn; j += i)
phi[j] = phi[j] / i * (i - );
for(int i = ; i < maxn; ++i) sum[i] = sum[i - ] + phi[i];
} int main()
{
euler();
while(scanf("%d", &n) && n)
write((sum[n] << ) - ), enter;
return ;
}

UVA10820 Send a Table的更多相关文章

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

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

  2. uva10820 send a table (nlogn求1-n欧拉函数值模版

    //重点就是求1-n的欧拉函数啦,重点是nlogn求法的版 //大概过程类似于筛选法求素数 #include<cstdio> #include<iostream> #inclu ...

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

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

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

  5. UVA10820 交表 Send a Table

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

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

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

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

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

  8. UVa 10820 - Send a Table

    题目:找到整数区间[1.n]中全部的互质数对. 分析:数论,筛法,欧拉函数.在筛素数的的同一时候.直接更新每一个数字的欧拉函数. 每一个数字一定会被他前面的每一个素数筛到.而欧拉函数的计算是n*π(1 ...

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

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

随机推荐

  1. RabbitMQ - 介绍

    RabbitMQ是个健壮.易用.开源.支持多种操作系统和语言的message broker. 当然,一切的前提是机器里面正在运行着rabbitmq-server. 点击下面的图片下载: rabbitM ...

  2. k8s安装部署过程个人总结及参考文章

    以下是本人安装k8s过程 一.单机配置 1. 环境准备 主机名 IP 配置 master1 192.168.1.181 1C 4G 关闭所有节点的seliux以及firewalld sed -i 's ...

  3. python打开文件常见错误及解决办法

    打开文件注意事项: 打开文件时需要,填写正确的路径,需要配置与文件相同的编码方式打开位机例如’utf-8‘,需要以特定 的模式打开文件 r, w,r+,w+,rb,wb,a, a+,ab等模式 f.o ...

  4. 【转】mouseover和mouseenter的区别

    一.当绑定着两个事件的元素里面没有子元素的时候,这两个事件的触发效果是一致的: x=0; y=0; $(document).ready(function(){ $("div.over&quo ...

  5. 新项目放到jenkins步骤

      1配置playbook.xml,src和dest需要和运维确认 2项目内config 文件夹下index文件内,build对象内assetsPublicPath属性是否需要更改.   playbo ...

  6. Java中的深拷贝和浅拷贝(转载)

    深拷贝(深复制)和浅拷贝(浅复制)是两个比较通用的概念,尤其在C++语言中,若不弄懂,则会在delete的时候出问题,但是我们在这幸好用的是Java.虽然java自动管理对象的回收,但对于深拷贝(深复 ...

  7. Android sqlite日期存储

    SQLite日期类型是以TEXT.REAL和INTEGER类型分别不同的格式表示的,对应如下:TEXT: "YYYY-MM-DD HH:MM:SS.SSS"REAL: 以Julia ...

  8. 自学git心得-2

    趁着最近还没忙起来,抓紧更新一下学习心得. 现在的情景是,我们已经在本地创建了一个Git仓库,又想在GitHub创建一个Git仓库,并且让这两个仓库进行远程同步,这样,GitHub上的仓库既可以作为备 ...

  9. PHP 多图片上传实例demo

    upload.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...

  10. 1.初次运行git前的配置

    在系统上安装了 Git后,你会想要做几件事来定制你的 Git 环境. 每台计算机上只需要配置一次,程序升级时会保留配置信息. 你可以在任何时候再次通过运行命令来修改它们. Git 自带一个 git c ...