廣告:這里的 e 是數(shù)學(xué)常數(shù),自然對(duì)數(shù)的底數(shù),無(wú)限不循環(huán)小數(shù)。這道題的意思就是,找出 e 中最先出現(xiàn)的 10 位質(zhì)數(shù),然后可以得出一個(gè)網(wǎng)址。進(jìn)入這個(gè)網(wǎng)址會(huì)看到 Google 為你出的第二道數(shù)學(xué)題,成功解鎖這步 Google 會(huì)告訴你,我們或許是”志同道合“的人,你可以將簡(jiǎn)歷發(fā)到這個(gè)郵箱,我們一起做點(diǎn)改變世界的事情。
計(jì)算 e 值可以通過(guò)泰勒公式推導(dǎo)出來(lái):e^x≈1 + x + x^2/2! + x^3/3! +……+ x^n/n! (1) 推導(dǎo)計(jì)算過(guò)程還包括埃拉托色尼篩選法(the Sieve of Eratosthenes)、線性篩選法的使用。感興趣的小伙伴可以用代碼實(shí)現(xiàn)下。
二、編程練習(xí)題
1. 斐波那契數(shù)列
@Testpublicvoidtest_Fibonacci(){int month =15;// 15個(gè)月long f1 =1L, f2 =1L;long f;for(int i =3; i < month; i++){
f = f2;
f2 = f1 + f2;
f1 = f;
System.out.println("第"+ i +"個(gè)月的兔子對(duì)數(shù): "+ f2);}}
@Testpublicvoidtest_ZhiYinShu(){f(200);}int k =2;publicvoidf(int n){while(k <= n){if(k == n){
System.out.println(n);break;}elseif(n > k && n % k ==
System.out.print(k +"*")
n = n / k;f(n);break;}elseif(n > k && n % k !=
k++;f(n);break;}}}
@Testpublicvoidtest_Prime(){int a =10, b =24;int m =division(a, b);int n = a * b / m;
System.out.println("最大公約數(shù): "+ m);
System.out.println("最小公倍數(shù): "+ n);}publicintdivision(int x,int y){int t;if(x < y){
t = x;
x = y;
y = t;}while(y !=0){if(x == y)return1;else{int k = x % y;
x = y;
y = k;}}return x;}
@Testpublicvoidtest_PerfectSquare(){for(long l =1L; l <100000; l++){if(Math.sqrt((l +100))%1==0){if(Math.sqrt((l +268))%1==0){
System.out.println(l +"加100是一個(gè)完全平方數(shù),再加168又是一個(gè)完全平方數(shù)");}}}}
@Testpublicvoidtest_solution(){
System.out.println("1到1000的完數(shù)有: ");for(int i =1; i <1000; i++){int t =0;for(int j =1; j <= i /2; j++){if(i % j ==0){
t = t + j;}}if(t == i){
System.out.print(i +" ");}}}
@Testpublicvoidtest_asum(){long a =2, b =0;
Scanner s =newScanner(System.in);int n = s.nextInt();int i =0;long sum =0;while(i < n){
b = b + a;
sum = sum + b;
a = a *10;++i;}
System.out.println("input number: "+ n);
System.out.println(sum);}
邏輯:定義一個(gè)變量b, 賦初值為0;定義一變量sum, 賦初值為0,進(jìn)入循環(huán)后,將a + b 的值賦給b,將sum + b 的值賦給sum;同時(shí),將a 增加十倍, ++ i; 繼續(xù)循環(huán);循環(huán)結(jié)束后,輸出sum 的值。
11. 無(wú)重復(fù)三位數(shù)
@Testpublicvoidtest_AC(){int count =0;for(int x =1; x <5; x++){for(int y =1; y <5; y++){for(int z =1; z <5; z++){if(x != y && y != z && x != z){
count++;
System.out.print(x *100+ y *10+ z +" ");if(count %4==0){
System.out.println();}}}}}
System.out.println("共有"+ count +"個(gè)三位數(shù)");}
publicclassSmallToBig{publicstaticvoidmain(String[] args){
SmallToBig fnc =newSmallToBig();int a, b, c;
System.out.println("Input 3 numbers:");
a = fnc.input();
b = fnc.input();
c = fnc.input();if(a > b){int t = a;
a = b;
b = t;}if(a > c){int t = a;
a = c;
c = t;}if(b > c){int t = b;
b = c;
c = t;}
System.out.println(a +" "+ b +" "+ c);}publicintinput(){int value =0;
Scanner s =newScanner(System.in);
value = s.nextInt();return value;}publicvoidcompare(int x,int y){// 此方法沒(méi)用if(x > y){int t = x;
x = y;
y = t;}}}
publicclassFenShu{publicstaticvoidmain(String[] args){int x =2, y =1, t;double sum =0;
DecimalFormat df =newDecimalFormat("#0.0000");for(int i =1; i <=20; i++){
sum +=(double) x / y;
t = y;
y = x;
x = y + t;
System.out.println("第 "+ i +" 次相加,和是 "+ df.format(sum));}}}
publicclassJieCheng{staticlong sum =0;staticlong fac =0;publicstaticvoidmain(String[] args){long sum =0;long fac =1;for(int i =1; i <=10; i++){
fac = fac * i;
sum += fac;}
System.out.println(sum);}}
publicclassHuiWen{publicstaticvoidmain(String[] args){
Scanner s =newScanner(System.in);
System.out.print("請(qǐng)輸入一個(gè)正整數(shù):");long a = s.nextLong();
String ss = Long.toString(a);char[] ch = ss.toCharArray();boolean is =true;int j = ch.length;for(int i =0; i < j /2; i++){if(ch[i]!= ch[j - i -1]){
is =false;}}if(is ==true){
System.out.println("這是一個(gè)回文數(shù)");}else{
System.out.println("這不是一個(gè)回文數(shù)");}}}
publicclassShunXu{publicstaticvoidmain(String[] args){
Scanner s =newScanner(System.in);int a = s.nextInt();int b = s.nextInt();int c = s.nextInt();if(a < b){int t = a;
a = b;
b = t;}if(a < c){int t = a;
a = c;
c = t;}if(b < c){int t = b;
b = c;
c = t;}
System.out.println("從大到小的順序輸出:");
System.out.println(a +" "+ b +" "+ c);}}
難度:???
題目:輸入3個(gè)數(shù)a,b,c,按大小順序輸出
19. 位置替換
publicclassTiHuan{staticfinalint N =8;publicstaticvoidmain(String[] args){int[] a =newint[N];
Scanner s =newScanner(System.in);int index1 =0, index2 =0;
System.out.println("please input numbers");for(int i =0; i < N; i++){
a[i]= s.nextInt();
System.out.print(a[i]+" ");}int max = a[0], min = a[0];for(int i =0; i < a.length; i++){if(a[i]> max){
max = a[i];
index1 = i;}if(a[i]< min){
min = a[i];
index2 = i;}}if(index1 !=0){int temp = a[0];
a[0]= a[index1];
a[index1]= temp;}if(index2 != a.length -1){int temp = a[a.length -1];
a[a.length -1]= a[index2];
a[index2]= temp;}
System.out.println("after swop:");for(int i =0; i < a.length; i++){
System.out.print(a[i]+" ");}}}
Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians. https://www.cs./users/EWD/transcriptions/EWD04xx/EWD498.html