Problem I. Count

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 42    Accepted Submission(s): 16

Problem Description
Multiple query, for each n, you need to get
n i-1
∑ ∑ [gcd(i + j, i - j) = 1]
i=1 j=1
 
Input
On the first line, there is a positive integer T, which describe the number of queries. Next there are T lines, each line give a positive integer n, as mentioned above.
T<=1e5, n<=2e7
 
Output
Your output should include T lines, for each line, output the answer for the corre- sponding n.
 
Sample Input
4
978
438
233
666
 
Sample Output
194041
38951
11065
89963
 
Source
 
Recommend
chendu   |   We have carefully selected several similar problems for you:  6437 6436 6435 6434 6433 
 
题意:求下面这个式子的值
n i-1
∑ ∑ [gcd(i + j, i - j) = 1]
i=1 j=1
分析:按照上面那个式子直接暴力打表容易得到上面式子的含义是1-n以内偶数的欧拉函数值加上奇数的欧拉函数值除以2的和(注意要快速打表,运用素数快速打表)
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 2*1e7+10;
const ll mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-8;
ll num[maxn], sum[maxn], prim[maxn];
int main() {
ios::sync_with_stdio(0);
ll T, n;
memset(num, 0, sizeof num);
num[1] = 1;
ll id = 0;
for( ll i = 2; i <= maxn-10; i ++ ) {
if(!num[i]) {
num[i] = i - 1; prim[id++] = i;
}
for( ll j = 0; j < id && prim[j]*i <= maxn-10; j ++ ) {
if(i % prim[j]) {
num[i*prim[j]] = num[i] * (prim[j]-1);
}
else {
num[i*prim[j]] = num[i] * prim[j];
break;
}
}
}
num[1] = 0;
sum[1] = 0;
for( ll i = 2; i <= maxn-10; i ++ ) {
if( i%2 == 0 ) {
sum[i] = sum[i-1] + num[i];
} else {
sum[i] = sum[i-1] + num[i]/2;
}
}
scanf("%lld",&T);
while( T -- ) {
scanf("%lld",&n);
printf("%lld\n",sum[n]);
}
return 0;
}

  

杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板的更多相关文章

  1. 杭电多校第十场 hdu6432 Cyclic 打表找规律

    Cyclic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Su ...

  2. 杭电多校第十场 hdu6435 CSGO 二进制枚举子集

    CSGO Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Subm ...

  3. Make Rounddog Happy(2019年杭电多校第十场1011+HDU6701+启发式分治)

    目录 题目链接 题意 思路 代码 题目链接 传送门 题意 求有多少个子区间满足\(a_l,a_{l+1},\dots,a_r\)均不相同且\(max(a_l,a_{l+1},\dots,a_r)-(r ...

  4. [2019杭电多校第十场][hdu6701]Make Rounddog Happy

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6701 题目大意为求满足 $max(a_{l},a_{l+1}\cdot \cdot \cdot a_{ ...

  5. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

  6. 2018杭电多校第三场1003(状态压缩DP)

    #include<bits/stdc++.h>using namespace std;const int mod =1e9+7;int dp[1<<10];int cnt[1& ...

  7. HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场

    题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> # ...

  8. HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场

    题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...

  9. HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场

    题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...

随机推荐

  1. hdoj 4712 Hamming Distance(靠人品过的)

    我先解释一下汉明距离  以下来自百度百科 在信息论中,两个等长字符串之间的汉明距离是两个字符串对应位置的字符不同的个数.换句话说,它就是将 一个字符串变换成另外一个字符串所需要替换的字符个数. 例如: ...

  2. UE4中UMG与C++交互 页面文本修改

    在UE4中,有两种方式创建ui,一种是使用slate的方式,一种是UMG,UMG是slate的封装,是一个可视化的ui编辑器.slate则是纯c++方式(之前实验过一次slate创建页面,代码相当麻烦 ...

  3. 【POJ - 3258】River Hopscotch(二分)

    River Hopscotch 直接中文 Descriptions 每年奶牛们都要举办各种特殊版本的跳房子比赛,包括在河里从一块岩石跳到另一块岩石.这项激动人心的活动在一条长长的笔直河道中进行,在起点 ...

  4. 大型系列课程之-七夕告白之旅vbs篇

    也许,世间所有的美好的东西,都是需要仪式感的,遇到了一年一度的七夕节,怎么过这个节日,成了很多心中有爱的人关注的事情,七夕不浪漫,人间不值得,七夕,发源于中国,这个美好的节日,来自动人的神话故事传说牛 ...

  5. SpringBoot 使用JPA时解决no session的方法

    1.在application.yml中添加 spring.jpa.open-in-view: true 2.在使用查询的方法添加 @Transactional

  6. UVA11388 GCD LCM

    (链接点这儿) 题目: The GCD of two positive integers is the largest integer that divides both the integers w ...

  7. java集合类的相关转换

    下面的的案例,基本上是以代码为主,文字的描述较少,后期有时间会继续添加. ArrayToList public void ArrayToList() { System.out.println(&quo ...

  8. java优雅注释原则和代码格式列举

    一.java的三种注释类型 单行注释:// ...... 块注释:/* ...... */ 文档注释:/** ...... */ 二.指导原则 注释不能美化糟糕的代码,碰到糟糕的代码就重新写吧. 用代 ...

  9. 纯数据结构Java实现(2/11)(栈与队列)

    栈和队列的应用非常多,但是起实现嘛,其实很少人关心. 但问题是,虽然苹果一直宣传什么最小年龄的编程者,它试图把编程大众化,弱智化,但真正的复杂问题,需要抽丝剥茧的时候,还是要 PRO 人士出场,所以知 ...

  10. Spring源码剖析9:Spring事务源码剖析

    转自:http://www.linkedkeeper.com/detail/blog.action?bid=1045 声明式事务使用 Spring事务是我们日常工作中经常使用的一项技术,Spring提 ...