日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5878】I Count Two Three(打表)

發布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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 123456789

Sample 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(打表)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。