博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
欧拉计划6-10题
阅读量:5897 次
发布时间:2019-06-19

本文共 4713 字,大约阅读时间需要 15 分钟。

6、

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

前十个自然数的平方和是:

1
2 + 2
2 + ... + 10
2 = 385

前十个自然数的和的平方是:

(1 + 2 + ... + 10)
2 = 55
2 = 3025

所以平方和与和的平方的差是3025 − 385 = 2640.

找出前一百个自然数的平方和与和平方的差。

#include 
#include
#include
#include
#define N 100 int powplus(int n, int k){ int s=1; while(k--) { s*=n; } return s;} int sum1(int n){ return powplus((n+1)*n/2,2);} int sum2(int n){ return (n*(n+1)*(2*n+1))/6;} void solve(){ printf("%d\n",sum1(N)); printf("%d\n",sum2(N)); printf("%d\n",sum1(N)-sum2(N));} int main(){ solve(); return 0;}
View Code
Answer:25164150
Completed on Tue, 2 Apr 2013, 06:57
 

 7、

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

前六个质数是2,3,5,7,11和13,其中第6个是13.

第10001个质数是多少?

#include 
#include
#include
#include
int prim(int n){ int i; for(i=2; i*i<=n; i++) { if(n%i==0) return 0; } return 1;} void solve(int n){ int i=2; int count=0; while(1) { if(prim(i)) { count++; if(count==n) break; } i++; } printf("%d\n",i);} int main(){ int n=10001; solve(n); return 0;}
View Code
Answer:104743

Completed on Thu, 4 Apr 2013, 17:34

 


 8、

Find the greatest product of five consecutive digits in the 1000-digit number.

73167176531330624919225119674426574742355349194934

96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450

找出以下这个1000位的整数中连续5个数字的最大乘积。(例如前五个数字的乘积是7*3*1*6*7=882)

#include 
#include
int main(){FILE *fp;char *buffer;int i=0,j=0;fp=fopen("E://file.txt","r");char c;while((c=fgetc(fp))){ if(c==EOF) break; else if(c!='\n') i++;}buffer=(char *)malloc(i*sizeof(char));rewind(fp);while((c=fgetc(fp))){ if(c==EOF) break; else if(c!='\n') { *(buffer+j)=c; j++; }}findmax(buffer,i);}int findmax(char *buffer,int i){ int j=0,max=0; for(j=0;j
View Code
Answer:40824
Completed on Sun, 17 Nov 2013, 11:16
 

 9、

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,

a
2 + 
b
2 = 
c
2

For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.

Find the product abc.

一个毕达哥拉斯三元组是一个包含三个自然数的集合,a<b<c,满足条件:

a
2 + 
b
2 = 
c
2

例如:32 + 42 = 9 + 16 = 25 = 52.

已知存在并且只存在一个毕达哥拉斯三元组满足条件a + b + c = 1000。

找出该三元组中abc的乘积。

#include
#include
#include
#include
#include
#include
void show(){ int a,b,c; for(a=1; a<333; a++) { for(c=333; c<500; c++) { b=1000-a-c; if(a*a+b*b==c*c) { printf("%d\n",a*b*c); return; } } }}int main(){ show(); return 0;}
View Code
Answer:31875000
Completed on Wed, 24 Jul 2013, 08:53
 

 10、

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

10以下的质数的和是2 + 3 + 5 + 7 = 17.

找出两百万以下所有质数的和。

#include
#include
#include
#define N 2000000bool prim(int n){ int i; for(i=2; i*i<=n; i++) { if(n%i==0) return false; } return true;}int main(){ int i; long long sum=2; for(i=3; i<=N; i=i+2) { if(prim(i)) { sum+=i; } } printf("%lld\n",sum); return 0;}
View Code
Answer:142913828922

Completed on Tue, 23 Jul 2013, 17:02

 

转载地址:http://rdxsx.baihongyu.com/

你可能感兴趣的文章
一点一点看JDK源码(二)java.util.List
查看>>
jquery 共用函数
查看>>
linux umount 提示device is busy 的解决
查看>>
C#操作Xml
查看>>
Zookeeper 应用
查看>>
Handler介绍:更新UI程序的方法
查看>>
算法学习(二):O(n^2)排序算法
查看>>
python-文件基本操作(一)
查看>>
iPhone XS 能否经受的起寒冬的考验
查看>>
LCT学习笔记
查看>>
玩转SSRS第九篇---匿名访问的一个间接方法
查看>>
SSIS典型应用场景分析
查看>>
ActiveMQ学习总结(8)——消息队列设计精要
查看>>
异步编程模式(三):等待异步调用的完成
查看>>
win7硬盘安装Ubuntu 14.04、Win7和Ubuntu双系统时卸载Ubuntu
查看>>
JS跨域ajax访问
查看>>
解决 CentOS网卡eth0启用不了问题
查看>>
VMWARE虚拟机CentOS6.4系统使用主机无线网卡上网的三种方法介绍
查看>>
dispatch 之 常见函数小结
查看>>
TYVJ2002 扑克牌
查看>>