嘟嘟嘟

【欧拉函数】

大致题意:如果知道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. java POST 传值 加签 验证

    话不多说,代码如下 package com.syl.test_key; import lombok.extern.slf4j.Slf4j; import org.apache.commons.code ...

  2. CMS gc随记

    在查看CMS相关中文资料时,都提到了 并发预清理(Concurrent precleaning) 重新标记(STW remark) 目的是重新标记在并发标记阶段,由于对象状态的改变而标记遗漏的对象. ...

  3. Eclipse 工具栏无法移动的解决办法

    升级到Juno后发现工具栏有些乱 而且无法拖动,试了下http://blog.csdn.net/cxx504659987/article/details/38532599的方法 发现配置文件里没有文中 ...

  4. JS实现中英文混合文字溢出友好截取功能

    在显示字符串的时候,避免字符串过长往往会对字符串进行截取操作,通常会用到js的 substr 或者 substring方法, 以及 字符串的length属性 substr() 方法可在字符串中抽取从 ...

  5. [android] 练习PopupWindow实现对话框

    练习使用Dialog实习对话框 package com.example.tsh; import android.app.Activity; import android.app.Dialog; imp ...

  6. 十二 Cent OS下 tomcat启动项目响应速度很慢

    在tomcat部署了web项目,每次启动项目都需要花费2-3分钟,甚至有的时候需要花费10分钟左右,实在是太慢了. 在网上查找解决方案,把 jdk/jre/lib/security/java.secu ...

  7. Springmvc file多附件上传 显示 删除操作

    之前项目需求要做一个多附件上传 并显示上传文件 带删除操作 一筹莫展之际搜到某个兄弟发的博客感觉非常好用被我copy下来了此贴算是改良版 再次感谢(忘记叫什么了时间也有点久没有历史记录了)先上图 基于 ...

  8. spring框架-----轻量级的应用开发框架

    一.bean 1.容器实例化 ApplicationContext ac=             new ClassPathXmlApplicationContext("applicati ...

  9. thinkphp多表联合查询

    1.两个表查询 $userid=session('user.id'); $user = M('cuser'); $data = $user->field('projectno')->whe ...

  10. es6 class类实例、静态、私有方法属性笔记

    实例属性.方法 class Foo { valueA = 100 //第一种实例属性定义,位置:new的实例上 constructor() { this.valueB = 200 //第二种实例属性定 ...