[hdu6434]Problem I. Count
题目大意:$T(T\leqslant 10^5)$组数据,每组数据给你$n(n\leqslant 2\times 10^7)$,求$\sum\limits_{i=1}^n\sum\limits_{j=1}^{i-1}[(i+j,i-j)==1]$
题解:
$$
\def\dsum{\displaystyle\sum\limits}
\begin{align*}
&\dsum_{i=1}^n\dsum_{j=1}^{i-1}[(i+j,i-j)=1]\\
&令k=i-j\\
=&\dsum_{i=1}^n\dsum_{k=1}^{i-1}[(2i-k,k)=1]\\
=&\dsum_{i=1}^n\dsum_{k=1}^{i-1}[(2i,k)=1]\\
\end{align*}
$$
$$
\therefore
(2i,k)=1\Rightarrow
\begin{cases}
(i,k)=1\\
(2,k)=1\\
\end{cases}\\
当i为偶数时:\\
(i,k)=1\\
\Rightarrow (2,k)=1\\
\therefore ans=\varphi(i)\\
当i为奇数时:\\
(2,k)=1\\
\Rightarrow k为奇数\\
\therefore k必为与i互质的数的奇数\\
\because (i,k)=1\Rightarrow(i,i-k)=1\\
\therefore 当i为奇数的时候,k奇偶各半\\
\therefore ans=\dfrac{\varphi(i)}2
$$
卡点:无
C++ Code:
#include <cstdio>
#define maxn 20000010
int Tim, n;
long long pre[maxn];
int plist[maxn << 3], pt, phi[maxn];
bool isp[maxn];
void sieve(int n) {phi[1] = 1;pre[1] = 0;isp[1] = true;for (int i = 2; i < n; i++) {if (!isp[i]) {plist[pt++] = i;phi[i] = i - 1;}for (int j = 0; j < pt && i * plist[j] < n; j++) {int tmp = i * plist[j];isp[tmp] = true;if (i % plist[j] == 0) {phi[tmp] = phi[i] * plist[j];break;}phi[tmp] = phi[i] * phi[plist[j]];}pre[i] = pre[i - 1] + ((i & 1) ? phi[i] / 1 : phi[i]);}
}
int main() {sieve(maxn);scanf("%d", &Tim);while (Tim --> 0) {scanf("%d", &n);printf("%lld\n", pre[n]);}return 0;
}
转载于:https://www.cnblogs.com/Memory-of-winter/p/9671153.html
[hdu6434]Problem I. Count相关推荐
- 杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板
Problem I. Count Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- LeetCode:Count Primes
Problem: Description: Count the number of prime numbers less than a non-negative number, n. Credits: ...
- 算法设计与分析第5章 回溯法(二)【回溯法应用】
第5章 回溯法 5.2 应用范例 1.0-1背包问题 有n件物品和一个容量为c的背包.第i件物品的重量是w[i],价值是p[i].求解将哪些物品装入背包可使这些物品的重量总和不超过背包容量,且价值总和 ...
- RMQ+1/-1算法
RMQ+1/-1问题要求数列中相邻两个元素相差+1或-1.利用这个限定条件可以使该算法复杂度总体上达到<O(n),O(1)>.具体做法是: 1) 设数列A的大小为n,先对数列A分组,每组大 ...
- RMQ+1/-1算法 [转]
[转] http://blog.csdn.net/ljsspace/article/details/6659517 RMQ+1/-1问题要求数列中相邻两个元素相差+1或-1.利用这个限定条件可以使该算 ...
- oracle11g ADR 位置
转自:http://blog.itpub.net/26110315/viewspace-717853/ 从oracle11g开始所有的诊断数据,包括alert log 都存储在ADR base 下.该 ...
- mapreduce代码示例_MapReduce算法示例
mapreduce代码示例 Welcome to MapReduce algorithm example. Before writing MapReduce programs in CloudEra ...
- CS188 Proj 1
更好的阅读体验 Project 1: Search Introduction In this project, your Pacman agent will find paths through hi ...
- 结对编程——队友项目分析
一.需求分析 1.项目名称:中小学数学卷子自动生成程序 2.用户:小学.初中和高中数学老师. 3.功能要求: (1)命令行输入用户名和密码,两者之间用空格隔开(程序预设小学.初中和高中各三个账号,具体 ...
最新文章
- 不错的工具:Reflector for .NET
- Vxworks、QNX、Xenomai、Intime、Sylixos、Ucos等实时操作系统的性能特点
- php window.onload,window.onload 触发时机问题
- RHCE笔记1-安裝
- lintcode 有效的括号序列
- 尘埃落定,初心未改——一个大学生的电子大赛感悟
- 【干货合集】看完这些干货,再说你因为“怕蛇”,所以学不好Python!
- yum install mysql-server 指定版本_mysql 指定版本安装
- python treeview控件使用详解_python绘图工具turtle库的使用详解
- 各地级市系列环境指标数据(2003-2017年)
- 关于微信小程序中的取整
- 支付宝支付后页面跳转
- nox模拟器(安卓5.1)adb连接
- |poj 3237|树链剖分|线段树|Tree
- 如何解决租房烦恼?阿里工程师写了一套神奇的代码
- Linux 流量控制TC
- JQuery实现图片点击放大
- HTML5 拖放Drag和drop用法以及事件介绍
- vite以及webpack(@vue/cli 5.x) vue3 alias别名配置
- Lesson 018 —— python 集合