欧拉工程第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 ...
随机推荐
- js----对象的创建
js创建对象的三种方法 在介绍之前一定要弄清楚一个概念,比如var a = new Object(); 这里的a并不是一个对象,而是一个对象的实例. 一.用Json创造 var a = {b:1,c: ...
- PHP连接SQL Server(sqlsrv)
配置好php环境后,下载如下依赖包,解压目录选择php的ext目录,并在php.ini中加上(我的php版本为5.6) extension=php_pdo_sqlsrv_56_ts.dll exten ...
- Waring:This LinearLayout layout or its FrameLayout parent is useless; transfer the background attribute to the other view
解决方法请参考: You have a single component (row) vertical linear layout, containing another linear layout. ...
- 正确处理WPF中Slider值改变事件的方式
最近在用WPF数据绑定重写一下播放器项目时遇到的关于Slider的问题,在窗体透明度调节和播放进度调节上用了Slider控件.调节窗体透明度我是 这么想的:将窗体的Opacity属性的值与Slider ...
- linux 标准io笔记
三种缓冲 1.全缓冲:在缓冲区写满时输出到指定的输出端. 比如对磁盘上的文件进行读写通常是全缓冲的. 2.行缓冲:在遇到'\n'时输出到指定的输出端. 比如标准输入和标准输出就是行缓冲, 回车后就会进 ...
- Java Day 03
比较运算符 & 逻辑运算符 > >= == < <= != instanceof & && | || ^ ! //逻辑运算符用于连接两个boo ...
- Ubuntu下的网络配置(USTC)
1. 配置静态ip ubuntu的网络配置信息放在 /etc/network/interfaces 中 sudo gedit /etc/network/interfacesauto lo 下 ...
- Objective-C传递数据小技巧
转自:http://www.guokr.com/blog/203413/ 比如说,如果你想向UIAlertView的delegate方法中传递一些信息,怎么办?继承UIAlertView么?使用Cat ...
- SQLServer调试
1.普通调试 直接点击SSMS客户端上的调试按钮即可 2.存储过程调试 2.1 定义存储过程(以Northwind数据库为例) USE [Northwind] GO /****** Object: S ...
- Exception in thread "http-bio-8081-exec-3" java.lang.OutOfMemoryError: PermGen space
前言: 在http://www.cnblogs.com/wql025/p/4865673.html一文中我曾描述这种异常也提供了解决方式,但效果不太理想,现在用本文的方式,效果显著. 目前此项目只能登 ...