0
点赞
收藏
分享

微信扫一扫

HDU 5878 - I Count Two Three 暴力打表+二分

徐一村 2023-02-07 阅读 49


Problem Description
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 i-th attacks failed if and only if i can be rewritten as the form of 2a3b5c7d which a,b,c,d are non-negative integers.

At recent dinner parties, we call the integers with the form 2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n.

Input
The first line of input contains an integer t (1≤t≤500000), the number of test cases. t test cases follow. Each test case provides one integer 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 n.

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

 

题意:给你一个n,给出 2^a * 3^b * 5^c 7^d的形式 且比输入数字>=的第一个数

暴力打表+二分

 

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
ll ans[100000];
ll quick_qow(ll a,ll b)///计算a^b %p
{
ll ans=1;///ans不能为1,b为0,p为1的情况不成立
for(;b;b>>=1)
{
if(b&1)
ans=(ans*a) ;
a=a*a ;
}
return ans;
}
int tot;
void init()
{
tot=0;
for(int i=0;i<32;i++)
{
if(quick_qow(7,i)>1000000000)break;
for(int j=0;j<32;j++)
{
if(quick_qow(7,i)*quick_qow(5,j)>1000000000)break;
for(int k=0;k<32;k++)
{
if(quick_qow(7,i)*quick_qow(5,j)*quick_qow(3,k)>1000000000)break;
for(int l=0;l<32;l++)
{
ll tmpp=quick_qow(2,l)*quick_qow(3,k)*quick_qow(5,j)*quick_qow(7,i);
if(tmpp>1000000000)break;
ans[tot++]=tmpp;
}
}
}
}
}
int main()
{
int t;
init();
sort(ans,ans+tot);
scanf("%d",&t);
while(t--)
{
ll n;
scanf("%lld",&n);
int mid;
ll anss=ans[lower_bound(ans,ans+tot,n)-ans];
printf("%lld\n",anss);
}
}

 

举报

相关推荐

0 条评论