51Nod1010 只包含因子2 3 5的數(打表+ lower_bound)
lower_bound這個函式挺好用的。
#include<iostream> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; const ll N=1e18+100; ll s[100000]; int m=0; void init() { ll i,j,k; for(i=1;i<N;i=i*2) for(j=1;j*i<N;j=j*3) for(k=1;k*i*j<N;k=k*5) s[m++]=i*j*k; } int main() { init(); int T; cin>>T; sort(s,s+m); while(T--) { ll a; cin>>a; cout<<*lower_bound(s+1,s+m,a)<<endl; } return 0; }
相關推薦
51Nod1010 只包含因子2 3 5的數(打表+ lower_bound)
lower_bound這個函式挺好用的。 #include<iostream> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; c
51nod1010----只包含因子2 3 5的數
思路: 因子只包含2 3 5的數字呢 往後找找 你會發現 並沒有很多 雖然範圍是1e18 但是符合條件的數字也並沒有超過1e6個 我們先預處理篩選一下 然後 剩下的問題就是查找了 用
51nod 1010 只包含因子2 3 5的數(打表+排序+二分)
F12 alt bbb art 打表 names syn tdi iostream 1010 只包含因子2 3 5的數 基準時間限制:1 秒 空間限制:131072 KB 分值: 10 難度:2級算法題 收藏 關註 取消關註 K的因子中只包含2 3
1007 正整數分組 1010 只包含因子2 3 5的數 1014 X^2 Mod P 1024 矩陣中不重復的元素 1031 骨牌覆蓋
str clu 重復 裏的 方法 class 如果 oid true 1007 正整數分組 將一堆正整數分為2組,要求2組的和相差最小。 例如:1 2 3 4 5,將1 2 4分為1組,3 5分為1組,兩組和相差1,是所有方案中相差最少的。 Input
51Nod 1010 只包含因子2 3 5的數 | 預處理+二分
black pri inf name ini 包含 def pac ++ Input示例 5 1 8 13 35 77 Output示例 2 8 15 36 80分析:將所有的只含有2 3 5因子的數打一個表保存在一個數組裏,然後二分查找第一個>=數組裏的數
只包含因子2 3 5的數(數論,二分,加醜數思想)
space priority tdi ins number 給定 個數 sin algorithm 個人心得:這題錯了很多很多次,一開始單純是想一直除2,3,5能除盡就可以了,但是數據太大,從第九組數據開始就超時了。 後面聽了隊友的意見打表,這裏用了醜數的思想,就是從2,3
只包含因子2 3 5的數(51nod 思維 打表)
K的因子中只包含2 3 5。滿足條件的前10個數是:2,3,4,5,6,8,9,10,12,15。 所有這樣的K組成了一個序列S,現在給出一個數n,求S中 >= 給定數的最小的數。 例如:n = 13,S中 >= 13的最小的數是15,所以輸出15。 Input 第1行:一個數T
【51Nod - 1010】【只包含因子2 3 5的數】
題目: K的因子中只包含2 3 5。滿足條件的前10個數是:2,3,4,5,6,8,9,10,12,15。 所有這樣的K組成了一個序列S,現在給出一個數n,求S中 >= 給定數的最小的數。 例如:n = 13,S中 >= 13的最小的數是15,所以輸出15。 Inpu
【51Nod - 1010 】只包含因子2 3 5的數 (打表,有坑越界)
題幹: K的因子中只包含2 3 5。滿足條件的前10個數是:2,3,4,5,6,8,9,10,12,15。 所有這樣的K組成了一個序列S,現在給出一個數n,求S中 >= 給定數的最小的數。 例如:n = 13,S中 >= 13的最小的數是15,所以輸出15。 Inpu
51Node 1010 只包含因子2 3 5的數 思維
題目 題意 思路 首先枚舉出所有滿足條件且不超過101810^{18}1018的數字,然後二分。 程式碼 #include <bits/stdc++.h> using namespac
醜數---只包含因子2、3和5的數
https://www.cnblogs.com/maleyang/articles/7495067.html 1 醜數---只包含因子2、3和5的數(根據已知求到結果,再把這個結果當成已知,求下一個結果) 2 //醜數 3 //把只包含因子2、3和5的數稱作醜數(U
尋找醜數,把只包含因子2、3和5的數稱作醜數(Ugly Number)
題目: 把只包含因子2、3和5的數稱作醜數(Ugly Number)。例如6、8都是醜數,但14不是,因為它包含因子7。 習慣上我們把1當做是第一個醜數。求按從小到大的順序的第N個醜數。 思路: 所
51nod 1082 與7無關的數 (打表預處理)
dao 空間 put ini spa 取消 memset blog ref 1082 與7無關的數 題目來源: 有道難題 基準時間限制:1 秒 空間限制:131072 KB 分值: 5 難度:1級算法題 收藏 關註 取消關註 一個正整數,如果它能被7整除,或
51nod 1062 序列中最大的數(打表預處理)
題目 with tdi .aspx input get 例如 ace mark 1062 序列中最大的數 題目來源: Ural 1079 基準時間限制:1 秒 空間限制:131072 KB 分值: 10 難度:2級算法題 收藏 關註 取消關註 有這
P1217 [USACO1.5]迴文質數 Prime Palindromes(打表輸出)
1.先編寫一個程式,求出5-100000000(一億)之間的迴文質數,並且輸出到檔案“huiwenzhishu.txt”,每兩個數字間用","隔開,方便第二個程式定義陣列時直接複製。 可以得到:5-100000000之間的迴文質數為799個,最小的為5,最大的為9989899 程式碼如下
小明數(打表)
Description 小明比較喜歡研究各種各樣的數字,有一天他發現了一類數,並將這些數命名為“小明數”,下面是“小明數”的定義:數字的二進位制由連續的k個1和連續的k-1個0組成。比如:1(二進位制為:1,k=1)6(二進位制為:110,k=2)120(二進位制為:1111000,k=4)496(二進位制為
幸運數 (打表)
幸運數是波蘭數學家烏拉姆命名的。它採用與生成素數類似的“篩法”生成 。 首先從1開始寫出自然數1,2,3,4,5,6,.... 1 就是第一個幸運數。 我們從2這個數開始。把所有序號能被2整除的項刪除,變為: 1 _ 3 _ 5 _ 7 _ 9 .... 把它們縮緊,重新記序,為: 1 3 5
51Nod 1010 只包含2 3 5的數
K的因子中只包含2 3 5。滿足條件的前10個數是:2,3,4,5,6,8,9,10,12,15。 所有這樣的K組成了一個序列S,現在給出一個數n,求S中 >= 給定數的最小的數。 例如:n = 13,S中 >= 13的最小的數是15,所以輸出15。 收起 輸入 第1
c語言:把只含因子2、3和5的數稱為醜數,求按從小到大的順序的第1500個醜數(兩種方法比較)
把只含因子2、3和5的數稱為醜數,求按從小到大的順序的第1500個醜數。例如6、8都是醜數,但14不是,因為它包含因子7。習慣上把1當作第1個醜數。演算法1:逐個判斷每個整數是不是醜數的解法,直觀但不夠高效#include<stdio.h>int ugly(int
與2,3,5無關的數
問題描述 定義與2,3,5無關的數如下: (1)位數不得是2,3,5的倍數; (2)該數不能被2,3,5整除; (3)該數必須為整數。 寫一個判斷一個數是否為與2,3,5無關的數的程式,如果有關,輸出“No”,如果無關,輸出“YeS”。 輸入格式 一行一個數。 輸出格式