hdu-6434-欧拉函数
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
n i-1
∑ ∑ [gcd(i + j, i - j) = 1]
i=1 j=1
T<=1e5, n<=2e7
978
438
233
666
38951
11065
89963
- #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-欧拉函数的更多相关文章
- hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion
http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...
- hdu 2654(欧拉函数)
Become A Hero Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 2824(欧拉函数)
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 1395(欧拉函数)
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 3307(欧拉函数+好题)
Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- 找新朋友 HDU - 1286 欧拉函数模板题
题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...
- hdu 2824 欧拉函数 O(nlogn) 和O(n)
裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using name ...
- hdu 4983 欧拉函数
http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = ...
- 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是 ...
- hdu 1787(欧拉函数)
GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- Jenkins-Publish HTML reports
创建job:testreport 在job中添加: 在Jenkins服务器上: 创建目录: .jenkins/jobs/{job名称}/workspace/htmlreports 注:此处job ...
- Latex: "Missing $ inserted" 解决方法
参考: Latex报"Missing $ inserted"的解决方法 Latex: "Missing $ inserted" 解决方法 原因一:在文中出现&q ...
- DPDK 网卡绑定和解绑
参考: DPDK网卡绑定和解绑 DPDK的安装与绑定网卡 DPDK 网卡绑定和解绑 注意: 建议不要使用本文的eth0网卡绑定dpdk驱动. 1.进入DPDK目录: $ cd dpdk/tools/ ...
- Java 静态方法不能重写但可以被子类静态方法覆盖
强调 静态方法是属于类的,只存在一份,会被该类的所有对象共享.不可以被重写. 静态方法可以被子类继承,但是不可以被子类重写 class door{ } class wood_Door extends ...
- 1、My Scripts
1.写一个包含命令.变量和流程控制的语句来清除/var/log的messages日志文件的shell脚本.(P26)(11-21) 2.利用$0和(dirname.basename)取出当前路径的目录 ...
- 关于PS抠图的各种方法 有这个就可以去面试了!!!加油!!!
今天和大家说说关于PS抠图的方法 高手也就如此 你值得拥有!!好了 废话不多说 下面进入正题 首先:我们得分析所给的图 然后运用不同的方法,当然也可以相互灵活运用 1:不抠图 2:万能抠图方法:快速 ...
- log4net配置使用
1.配置文件 app.config <?xml version="1.0" encoding="utf-8" ?> <configuratio ...
- Python 模块(module)
模块(module)也是为了同样的目的.在Python中,一个.py文件就构成一个模块.通过模块,你可以调用其它文件中的程序. first.py def laugh(): print "Ha ...
- C/C++.全文件名全路径名分割拆分分解
1._splitpath ZC:windows api的话 可以使用 PathFindFileNameA.PathFindExtensionA.PathFileExistsA等一系列函数 2.测试代码 ...
- VC_窗口exe_printf信息
1. #include <io.h> #include <fcntl.h> #include <stdio.h> 2. void InitConsoleWindow ...