藍橋杯 ADV-91 演算法提高 素數判斷
編寫一函式IsPrime,判斷某個大於2的正整數是否為素數。
樣例輸入:
5
樣例輸出:
yes
樣例輸入:
9
樣例輸出:
no
注意:是素數輸出yes,不是素數輸出no,其中yes和no均為小寫。
#include <iostream> using namespace std; int main() { int n; cin >> n; for(int i = 2; i * i <= n; i++) { if(n % i == 0) { cout << "no"; return 0; } } cout << "yes"; return 0; }
相關推薦
藍橋杯 ADV-91 演算法提高 素數判斷
編寫一函式IsPrime,判斷某個大於2的正整數是否為素數。樣例輸入: 5樣例輸出:yes樣例輸入: 9樣例輸出:no注意:是素數輸出yes,不是素數輸出no,其中yes和no均為小寫。 #incl
藍橋杯 ADV-184 演算法提高 素數求和
問題描述 輸入一個自然數n,求小於等於n的素數之和樣例輸入2樣例輸出2資料規模和約定 測試樣例保證 2 <= n <= 2,000,000 #include <iostream> using namespace std; int v[20000
藍橋杯 ADV-21 演算法提高 多項式輸出
問題描述一元n 次多項式可用如下的表示式表示: f(x)=a[n]x^n+a[n-1]x^(n-1)+...+a[1]x+a[0], a[n]!=0 其中,a[i]x^i稱為i 次項, a[i]稱為i 次項的係數。給出一個一元多項式各項的次數和係數,請按照如下規定的格式要求輸出該多項式: 1.
[Java] 藍橋杯ADV-136 演算法提高 大數加法
問題描述輸入兩個正整數a,b,輸出a+b的值。輸入格式兩行,第一行a,第二行b。a和b的長度均小於1000位。輸出格式一行,a+b的值。樣例輸入4 2樣例輸出6 package adv136; im
[Java] 藍橋杯ADV-135 演算法提高 三角形面積
問題描述由三角形的三邊長,求其面積。 提示:由三角形的三邊a,b,c求面積可以用如下的公式: s=(a+b+c)/2 面積= 輸入格式由空格分開的三個整數。輸出格式一個實數,保留兩位小數。樣例輸入
[Java] 藍橋杯ADV-194 演算法提高 盾神與積木遊戲
問題描述最近的m天盾神都去幼兒園陪小朋友們玩去了~ 每個小朋友都拿到了一些積木,他們各自需要不同數量的積木來拼一些他們想要的東西。但是有的小朋友拿得多,有的小朋友拿得少,有些小朋友需要拿到其他小朋友的積
[Java] 藍橋杯ADV-203 演算法提高 8皇后·改
問題描述規則同8皇后問題,但是棋盤上每格都有一個數字,要求八皇后所在格子數字之和最大。輸入格式一個8*8的棋盤。輸出格式所能得到的最大數字和樣例輸入1 2 3 4 5 6 7 89 10 11 12 1
[Java] 藍橋杯ADV-202 演算法提高 最長公共子序列
問題描述給定兩個字串,尋找這兩個字串之間的最長公共子序列。輸入格式輸入兩行,分別包含一個字串,僅含有小寫字母。輸出格式最長公共子序列的長度。樣例輸入abcdgh aedfhb樣例輸出3樣例說明最長公共子
[Java] 藍橋杯ADV-185 演算法提高 五次方數
問題描述對一個數十進位制表示時的每一位數字乘五次方再求和,會得到一個數的五次方數 例如:1024的五次方數為1+0+32+1024=1057 有這樣一些神奇的數,它的五次方數就是它自己,而且這樣的數竟然
藍橋杯 ADV-188 演算法提高 排列數(java) 深度優先搜尋 DFS
演算法提高 排列數 時間限制:1.0s 記憶體限制:256.0MB 問題描述 0、1、2三個數字的全排列有六種,按照字母序排列如下: 012、021、102、120、201、210 輸入一個數n 求0~9十個數的全排列中的第n個(
藍橋杯 ADV-62演算法提高 奪寶奇兵(動態規劃)
[題目描述] 在一座山上,有很多很多珠寶,它們散落在山底通往山頂的每條道路上,不同道路上的珠寶的數目也各不相同.下圖為一張藏寶地圖: 7 3 8 8 1 0 2 7 4 4 4 5
藍橋杯 ADV-208 演算法提高 矩陣相乘
問題描述 小明最近在為線性代數而頭疼,線性代數確實很抽象(也很無聊),可惜他的老師正在講這矩陣乘法這一段內容。 當然,小明上課打瞌睡也沒問題,但線性代數的習題可是很可怕的。 小明希望你來幫他完成這個任務。 現在給你一個ai行aj列的矩陣和一個bi行bj列的矩陣
藍橋杯 ADV-68演算法提高 企業獎金髮放
企業發放的獎金根據利潤提成。利潤低於或等於10萬元時,獎金可提10%;利潤高於10萬元,低於20萬元時,低於10萬元的部分按10%提成,高於10萬元的部分,可提成7.5%;20萬到40萬之間時,高於
藍橋杯 ADV-127 演算法提高 日期計算(java)
演算法提高 日期計算 時間限制:1.0s 記憶體限制:256.0MB 問題描述 已知2011年11月11日是星期五,問YYYY年MM月DD日是星期幾?注意考慮閏年的情況。尤其是逢百年不閏,逢400年閏的情況。 輸入格式 輸入只有一行
藍橋杯 ADV-77 演算法提高 統計平均成績
有4個學生,上4門課,要求輸入全部學生的各門課成績,並分別求出每門課的平均成績。(保留2位小數) 括號裡是解釋內容,不用輸入輸出。輸入的所有數都為0到100之間(包括端點)的整數樣例輸入(輸入第1
演算法提高 素數判斷
編寫一函式IsPrime,判斷某個大於2的正整數是否為素數。樣例輸入: 5樣例輸出:yes樣例輸入: 9樣例輸出: no注意:是素數輸出yes,不是素數輸出no,其中yes和no均為小寫。 #inc
藍橋杯練習:演算法提高 佇列操作
問題描述 佇列操作題。根據輸入的操作命令,操作佇列(1)入隊、(2)出隊並輸出、(3)計算隊中元素個數並輸出。 輸入格式 第一行一個數字N。 下面N行,每行第一個數字為操作命令(
藍橋杯 演算法提高 素數求和
問題描述 輸入一個自然數n,求小於等於n的素數之和 樣例輸入 2 樣例輸出 2 資料規模和約定 測試樣例保證 2 <= n <= 2,000,000 解題思路 很簡單一個東西,使用一個迴圈,當前這個數如果為素數的話就將這個數加入到 和 裡面 //問題
演算法提高 素數求和 藍橋杯 (篩選法)
/* 演算法提高 素數求和 問題描述 輸入一個自然數n,求小於等於n的素數之和樣例輸入2樣例輸出2資料規模和約定 測試樣例保證 2 <= n <= 2,000,000*/#include <stdio.h>#include <stdlib
藍橋杯 ALGO-61 演算法訓練 奇偶判斷
演算法訓練 奇偶判斷 時間限制:1.0s 記憶體限制:512.0MB 問題描述 能被2整除的數稱為偶數,不能被2整除的數稱為奇數。給一個整數x,判斷x是奇數還是偶數。 輸入格式 輸入包括