标签:nts color com ini output -o blank inf data
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 2^a3^b5^c7^d2a3b5c7d which a,\ b,\ c,\ da, b, c, d are non-negative integers.
At recent dinner parties, we call the integers with the form 2^a3^b5^c7^d2a3b5c7d "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.
The first line of input contains an integer t (1\le t \le 500000)t(1≤t≤500000), the number of test cases. tt test cases follow. Each test case provides one integer n (1\le n\le 10^9)n(1≤n≤109).
For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than nn.
10 1 11 13 123 1234 12345 123456 1234567 12345678 123456789
1 12 14 125 1250 12348 123480 1234800 12348000 123480000
ACM-ICPC 2016 Qingdao Preliminary Contest
这道题类似于之前的51Nod - 1284找2 3 5 7的倍数,求出2 3 5 7最小公倍数210找循环节。
本题是2^a*3^b*5^c*7^d,无法从gcd循环节入手,于是就把10^9之内满足条件的值打出表来,发现只有5194个。
由于t很大,将表排个序,二分查找即可。
#include<stdio.h> #include<algorithm> #define MAX 5200 #define INF 0x3f3f3f3f using namespace std; typedef long long ll; ll a[MAX]; ll mul(ll init,int x,int c) { ll ans=init; for(int i=1;i<=c;i++){ ans*=x; if(ans>1000000000) return 0; } return ans; } int main() { int t,i,j,k,l; int tt=0; for(i=0;i<=31;i++){ ll ii=mul(1,2,i); if(ii==0) continue; for(j=0;j<=31;j++){ ll jj=mul(ii,3,j); if(jj==0) continue; for(k=0;k<=31;k++){ ll kk=mul(jj,5,k); if(kk==0) continue; for(l=0;l<=31;l++){ ll lll=mul(kk,7,l); if(lll==0) continue; a[++tt]=lll; } } } } sort(a+1,a+tt+1); ll n; scanf("%d",&t); while(t--){ scanf("%lld",&n); ll ans=INF; int l=1,r=tt,m; while(l<=r){ m=(l+r)/2; if(a[m]==n){ ans=n; break; } if(a[m]<n){ l=m+1; } else{ if(a[m]<ans) ans=a[m]; r=m-1; } } printf("%lld\n",ans); } return 0; }
2016青岛网络赛 I Count Two Three(打表+二分)
标签:nts color com ini output -o blank inf data
原文地址:https://www.cnblogs.com/yzm10/p/9477438.html