Problem I. Count

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

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
    ∑i=1ni-1j=1 [gcd(i + j, i − j) = 1]
  =  [gcd(2i-a,a)=1]    (1<=i<=n,1<=a<i)
  =  [gcd(2i,a)=1]    (1<=i<=n,1<=a<i)
即对于每个 i, 求有多少个小于它的 a 满足 gcd(i, a) = 1 且a是奇数。
当i是偶数的时候贡献就是  phi(i) ,因为偶数与偶数一定不互质。
当i是奇数的时候贡献是phi(i)/2 ,因为i是奇数,假如x与i互质那么 i-x与i也互质,且x与i-x一个是奇数一个是偶数,所以数量是均等出现的。
 #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define inf 0x7fffffffff
#define pii pair<int,int>
const int maxn=;
vector<int>prime;
bool is[maxn];
LL f[maxn];
void init(){
f[]=;
is[]=is[]=;
for(int i=;i<=maxn;++i){
if(!is[i]) prime.push_back(i),f[i]=i-;
for(int j=;j<prime.size()&&1LL*i*prime[j]<=maxn;++j){
is[i*prime[j]]=;
if(i%prime[j]==){
f[i*prime[j]]=f[i]*prime[j];
break;
}
else{
f[i*prime[j]]=f[i]*(prime[j]-);
}
}
}
for(int i=;i<maxn;++i){
if(i&)f[i]/=;
f[i]+=f[i-];
}
} int main()
{
init();
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
printf("%lld\n",f[n]);
}
return ;
}

hdu-6434-欧拉函数的更多相关文章

  1. hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion

    http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...

  2. hdu 2654(欧拉函数)

    Become A Hero Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. hdu 2824(欧拉函数)

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. hdu 1395(欧拉函数)

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. hdu 3307(欧拉函数+好题)

    Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  6. 找新朋友 HDU - 1286 欧拉函数模板题

    题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...

  7. hdu 2824 欧拉函数 O(nlogn) 和O(n)

    裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using name ...

  8. hdu 4983 欧拉函数

    http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = ...

  9. hdu 4002 欧拉函数 2011大连赛区网络赛B

    题意:求1-n内最大的x/phi(x) 通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是 ...

  10. hdu 1787(欧拉函数)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. 论文笔记之:Optical Flow Estimation using a Spatial Pyramid Network

    Optical Flow Estimation using a Spatial Pyramid Network   spynet  本文将经典的 spatial-pyramid formulation ...

  2. Twitter开发

    开发文档:https://developer.twitter.com/ the Twitter Developer Account Application 示例:https://wptweetboos ...

  3. RequestMethod用法小结和注意事项

    本文为博主原创,未经允许不得转载: RequestMethod为在@RequestMapping注解中使用的一个属性,用来标识请求的方法类型,可参考@RequestMapping源码: @Target ...

  4. [小问题笔记(九)] SQL语句Not IN 效率低,用 NOT EXISTS试试

    项目中遇到这么个情况: t1表 和 t2表  都是150w条数据,600M的样子,都不算大. 但是这样一句查询 ↓ select * from t1 where phone not in (selec ...

  5. SAP应用创新-维护控制表、视图统一路径

    SAP应用创新-维护控制表.视图统一路径 背景: Sap 里面通过技术支持人员维护表的值控制业务操作的表不少,一般通过事物代码或记录在系统外的文档或在某个程序上放置一个按钮.缺点:分散,不易记,不好找 ...

  6. 【OJ】字符串去重并并按原顺序打印出重复字符

    ACM上一道简单的字符串题,从网上找了下类似的代码进行参考外加之个人思考,想到此好思路. 题目大意 任意输入一行字符串,检索重复出现的字符.将原字符串中的重复字符删除后按照原顺序输出,同时按照原顺序输 ...

  7. WaitingFormHelper

    using Lba_Ciac; using System; using System.Collections.Generic; using System.Linq; using System.Text ...

  8. 【Python】【jupyter-notebook】

    1. win7 安装:https://www.cnblogs.com/zlslch/p/6984403.html 1.Jupyter Notebook 和 pip   为了更加方便地写 Python ...

  9. 【BZOJ】3295: [Cqoi2011]动态逆序对

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3295 mamaya,弱鸡xrdog终于会写树套树啦.... 将树状数组中每一个节点看成一棵 ...

  10. IO模型——IO多路复用机制

    (1)I/O多路复用技术通过把多个I/O的阻塞复用到同一个select.poll或epoll的阻塞上,从而使得系统在单线程的情况下可以同时处理多个客户端请求.与传统的多线程/多进程模型比,I/O多路复 ...