欧拉工程第72题:Counting fractions
题目链接:https://projecteuler.net/problem=72
真分数;n/d
当d ≤ 1,000,000时候的真分数有多少个
public class P72{
void run(){
int max_n = 1000000;
long[] phi = cal_phi(max_n+1);
long sum=0;
phi[1] = 0;
for(int i =1;i<=max_n;i++)
sum+=phi[i];
System.out.println(sum);
}
// 303963552391
// 194ms
long[] cal_phi(int max_n){
long[] phi = new long[max_n+1];
for(int i=1;i<max_n;i++){
phi[i] += i;
for(int j =2*i;j<max_n;j+=i)
phi[j]-=phi[i];
}
return phi;
}
public static void main(String[] args){
long t0 = System.currentTimeMillis();
new P72().run();
long t1= System.currentTimeMillis();
System.out.println((t1-t0)+"ms");
}
}
欧拉工程第72题:Counting fractions的更多相关文章
- 欧拉工程第69题:Totient maximum
题目链接 欧拉函数φ(n)(有时也叫做phi函数)可以用来计算小于n 的数字中与n互质的数字的个数. 当n小于1,000,000时候,n/φ(n)最大值时候的n. 欧拉函数维基百科链接 这里的是p是n ...
- 欧拉工程第70题:Totient permutation
题目链接 和上面几题差不多的 Euler's Totient function, φ(n) [sometimes called the phi function]:小于等于n的数并且和n是互质的数的个 ...
- 欧拉工程第73题:Counting fractions in a range
题目链接:https://projecteuler.net/problem=73 n/d的真分数 ,当d<=12000时 在 1/3 and 1/2 之间的有多少个 public class P ...
- 欧拉工程第71题:Ordered fractions
题目链接:https://projecteuler.net/problem=71 If n<d and HCF(n,d)=1, it is called a reduced proper fra ...
- 欧拉工程第67题:Maximum path sum II
By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma ...
- 欧拉工程第66题:Diophantine equation
题目链接 脑补知识:佩尔方差 上面说的貌似很明白,最小的i,对应最小的解 然而我理解成,一个循环的解了,然后就是搞不对,后来,仔细看+手工推导发现了问题.i从0开始变量,知道第一个满足等式的解就是最小 ...
- 欧拉工程第65题:Convergents of e
题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...
- 欧拉工程第56题:Powerful digit sum
题目链接 Java程序 package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; im ...
- 欧拉工程第55题:Lychrel numbers
package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; import java.util ...
随机推荐
- 模拟抛硬币(C语言实现)
实现代码: #include<stdio.h> #include<stdlib.h> int heads() { ; } int main(int argc, char *ar ...
- C++安装失败解决办法
法一:删除注册表中的HKY_LOCAL_MACHINE\\SYSTEM|ControlSet001\\Services\\VSS,卸载重装.法二:点击 setup目录下的 wpie15.exe .. ...
- HMTL5的 video 在IOS7中碰到的坑
直接说问题吧, 测试设备,ipod 我们在移动端播放视频的时候,一般使用H5的video标签,OK,这里有几点差异(就我目前所发现的)给大家分享一下, 1.在IOS7中,video元素是需要确定大小的 ...
- C#中Split函数的使用
Split函数 描述 :返回一个下标从零开始的一维数组,它包含指定数目的子字符串. 语法 :Split(expression[, delimiter[, count[, compare]] ...
- perl编程中的map函数示例
转自:http://www.jbxue.com/article/14854.html 发布:脚本学堂/Perl 编辑:JB01 2013-12-20 10:20:01 [大 中 小] 本文介绍 ...
- mysql rand随机查询记录效率
一直以为mysql随机查询几条数据,就用 SELECT * FROM `table` ORDER BY RAND() LIMIT 5 就可以了. 但是真正测试一下才发现这样效率非常低.一个15万余条的 ...
- PHP流程控制语句下
ok,继续搞. while循环: while(expr){ 程序块: } 条件expr成立执行程序块,否则结束. do while循环:do while循环比while循环要多循环一次,它要先执行程序 ...
- Windows下关于Composer使用时出现的问题及解决办法
问题一: Fatal error: Call to undefined method Composer\Package\CompletePackage::getTrans portOptions() ...
- SqlServer ,storedprocedure操作
USE [Role] GO /*Create a table*/ IF OBJECT_ID ('dbo.Users', 'U') IS NOT NULL DROP TABLE Users GO CRE ...
- Google面试题及答案
1. 村子里有100对夫妻,其中每个丈夫都瞒着自己的妻子偷情...村里的每个妻子都能立即发现除自己丈夫之外的其他男人是否偷情,唯独不知道她自己的丈夫到底有没有偷情.村里的规矩不容忍通奸.任何一个妻子, ...