【HDU - 5878】I Count Two Three(打表)
題干:
I will show you the most popular board game in the Shanghai Ingress Resistance Team.
It all started several months ago.?
We found out the home address of the enlightened agent Icount2three and decided to draw him out.?
Millions of missiles were detonated, but some of them failed.?
After the event, we analysed the laws of failed attacks.?
It's interesting that the?ii-th attacks failed if and only if?ii?can be rewritten as the form of?2a3b5c7d2a3b5c7d?which?a,b,c,da,b,c,d?are non-negative integers.?
At recent dinner parties, we call the integers with the form?2a3b5c7d2a3b5c7d?"I Count Two Three Numbers".?
A related board game with a given positive integer?nn?from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than?nn.
Input
The first line of input contains an integer?t?(1≤t≤500000)t?(1≤t≤500000), the number of test cases.?tt?test cases follow. Each test case provides one integer?n?(1≤n≤109)n?(1≤n≤109).
Output
For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than?nn.
Sample Input
10 1 11 13 123 1234 12345 123456 1234567 12345678 123456789Sample Output
1 12 14 125 1250 12348 123480 1234800 12348000 123480000題目大意:
定義一組數,數是只含有2357四個因子。5e5次詢問,每次詢問一個x,讓你輸出這一組數中大于等于x的第一個數。
解題報告:
? 對這組數打表,然后對于查詢直接二分就行了。注意打表的時候可能爆longlong所以需要邊打表邊剪枝。
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; ll a2[33],a3[33],a5[33],a7[33]; const ll INF = 1e9; int tot; ll db[MAX]; int main() {int t;ll a2=1,a3=1,a5=1,a7=1,n;for(ll i = 1; i<=33; i++,a2*=2) {ll tmp = a2;a3=1;for(ll j = 1; j<=33; j++,a3*=3) {tmp=a2*a3;if(tmp > INF) break;a5=1;for(int k = 1; k<=33; k++,a5*=5) {tmp=a2*a3*a5;if(tmp > INF) break;a7=1;for(int q = 1; q<=33; q++,a7*=7) {tmp=a2*a3*a5*a7;if(tmp > INF) break;db[++tot] = tmp;}}}}sort(db+1,db+tot+1);cin>>t;while(t--) {scanf("%lld",&n);int pos = lower_bound(db+1,db+tot+1,n) - db;printf("%lld\n",db[pos]);}return 0 ; }?
總結
以上是生活随笔為你收集整理的【HDU - 5878】I Count Two Three(打表)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【POJ - 3281】Dining(拆
- 下一篇: 在银行存1万5,一年利息只有40元?存错