素數的判斷。
/*Goldbach's Conjecture Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21888 Accepted: 8714 Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be written as the sum of two odd prime numbers. For example: 8 = 3 + 5. Both 3 and 5 are odd prime numbers. 20 = 3 + 17 = 7 + 13. 42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23. Today it is still unproven whether the conjecture is right. (Oh wait, I have the proof of course, but it is too long to write it on the margin of this page.) Anyway, your task is now to verify Goldbach's conjecture for all even numbers less than a million. Input The input will contain one or more test cases. Each test case consists of one even integer n with 6 <= n < 1000000. Input will be terminated by a value of 0 for n. Output For each test case, print one line of the form n = a + b, where a and b are odd primes. Numbers and operators should be separated by exactly one blank like in the sample output below. If there is more than one pair of odd primes adding up to n, choose the pair where the difference b - a is maximized. If there is no such pair, print a line saying "Goldbach's conjecture is wrong." Sample Input 8 20 42 0 Sample Output 8 = 3 + 5 20 = 3 + 17 42 = 5 + 37 */ #include <stdio.h> #include <string.h> #include "math.h" #define MAX_INPUT_NUMBER 1000001 #define MAX_CONSECUTIVE_PRIME_NUMBER 78498 #define PRIME_TRUE 1 #define PRIME_FALSE 0 typedef unsigned char PRIME_BOOL; PRIME_BOOL gabPrimeList[MAX_INPUT_NUMBER]; int gaiConsecutivePrime[MAX_CONSECUTIVE_PRIME_NUMBER]; int GoldbachsConjecturemain(void) { int iPrimeNum = 0; int iInteger; int iMaxFactor; int iLoop; memset(gabPrimeList,PRIME_FALSE,MAX_INPUT_NUMBER*sizeof(PRIME_BOOL)); gabPrimeList[2] = PRIME_TRUE; gaiConsecutivePrime[iPrimeNum] = 2; iPrimeNum++; for (iInteger = 3; iInteger < MAX_INPUT_NUMBER; iInteger+=2 ) { iMaxFactor = (int)sqrt(iInteger); for (iLoop = 3; iLoop <= iMaxFactor; iLoop+=2) { if (0 == iInteger%iLoop) { break; } } if (iLoop > iMaxFactor) { gaiConsecutivePrime[iPrimeNum] = iInteger; iPrimeNum++; gabPrimeList[iInteger] = PRIME_TRUE; } } while(1) { scanf("%d",&iInteger); if (0 == iInteger) { break; } for (iLoop = 0; gaiConsecutivePrime[iLoop] <= iInteger/2; iLoop++ ) { if (gabPrimeList[iInteger - gaiConsecutivePrime[iLoop]] == PRIME_TRUE) { printf("%d = %d + %d/n",iInteger,gaiConsecutivePrime[iLoop],iInteger - gaiConsecutivePrime[iLoop]); break; } } if (gaiConsecutivePrime[iLoop] > iInteger/2) { printf("Goldbach's conjecture is wrong./n"); } } return 0; }
零拷貝技術(Zero-Copy)是一個大家耳熟能詳的技術名詞了,它主要用於提升 IO(Input & Output)的傳輸性能。 那麼問題來了,爲什麼零拷貝技術能提升 IO 性能? 1.零拷貝技術和性能 在傳統的 IO 操作中,當我們需要讀
Popover API 爲開發者提供了一種聲明式的方式來創建各種類型的彈窗。目前已在所有三大瀏覽器引擎中可用,並正式成爲 Baseline 2024 的一部分。 一直以來,我們在實現彈出式菜單、提示框或信息卡片時,往往依賴於各種JavaSc
現在,使用視頻會議系統遠程協同辦公、溝通交流,已經非常普遍了。如果我們要開發自己的視頻會議系統,那麼,GPU解碼渲染技術是不可缺少的。 在視頻會議系統中,經常需要同時觀看會議中多個參會人員的視頻圖像,另外,還可能需要
前言 公衆號每月定期推廣和分享的C#/.NET/.NET Core優秀項目和框架(每週至少會推薦兩個優秀的項目和框架當然節假日除外),公衆號推文中有項目和框架的介紹、功能特點、使用方式以及部分功能截圖等(打不開或者打開GitHub很慢的同
【最近想做什麼了】 和之前一樣,模板還是跳槽 【爲什麼要做這個】 和之前一樣,但是還是想再寫一遍 現在的工作,錢少事多離家遠 現在的自己,人窮有家要搞錢 【要在什麼時間達到什麼樣的目標,分段計劃是怎樣的】 目前可信考試是過了, 太簡單了,算
【今天又是什麼日子】 今天是2024年6月7日,星期五,其實也沒有很特別 只不過剛好是今年高考的第一天,寫這個的時候上午的考試應該完了 高考很重要,每一天都很重要 年輕很好,每一天也很好 且行且珍惜 【上次來是什麼時候】 上次來還是上個月月
官網安裝後, vscode會自動識別. 右下角選go.(不能選go module) 然後安裝go插件.之後運行即可. 如果自動安裝delve啥的出錯. 就先自己配置. go env -w GOPROXY=https://goproxy.cn
前言 jdk1.8的docker鏡像默認是cpu架構爲x64的,在arm架構或者aarch64 上運行java應用需要自己構建一個對應cpu架構的jdk基礎鏡像 過程 首先去Oracle官網下載對應的Arm架構的1.8版本jdk 下載好後
什麼是RPA RPA(機器人流程自動化)系統是一種應用程序,它通過模仿用戶在電腦上的操作方法, 實現自動化操作流程, 協助人在計算機、手機等計算設備中完成重複的工作流任務。 Power Automate Desktop 2021年3月2日
Power Automate Desktop 安裝完,登錄後老是提示one driver 錯誤
https://www.edx.org/edxchina https://www.coursera.org/ https://www.xuetangx.com/search?query=%E9%83%91%E6%AF%93%E7%
【0】資源配置文件 [root@mcwk8s03 mcwtest]# ls mcwdeploy.yaml [root@mcwk8s03 mcwtest]# cat mcwdeploy.yaml apiVersion: apps/v1 k
異常攔截器ExceptionMapper 在JAX-RS(Java API for RESTful Web Services)中,ExceptionMapper接口用於將Java異常映射到HTTP響應。通過實現ExceptionMapper
從最初的CS架構,如MFC Java Swing 等,到BS架構,JSP PHP,再到前端後端分離,前端從jquery GWT-Ext 到 Handlebars ,再到angularJS/Vue/React,反觀java 世界,學好 S