51Nod1010解题报告

题目地址:

  https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010

题目概述:

  以后51Nod的题面都省略了。

大致思路:

  读完题之后感觉水水的暴力啊,交了一发T,然后发现暴力爆精度了,改了精度WA,然后打算写另外一个暴力,TLE。

  看了一下数据,发现还是WA在了精度上,改了之后过了。

  不甘心的我去看了看正解,发现只含有2、3、5因子的数竟然不会超过343000!!!建议你们还是预处理加二分吧。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <assert.h>
#include <stack>
#include <set>
#include <bitset>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;

#define sacnf scanf
#define scnaf scanf
#define scnafi scanfi
#define pb push_back
#define Len size()
#define gchar getchar()
#define FOR(i,j,k) for(int (i)=(j);(i)<=(k);(i)++)
#define mes(a,b) memset((a),(b),sizeof(a))
#define scanfi(a) scanf("%d",&(a))
#define scanfti(a,b) scanf("%d%d",&(a),&(b))
#define println(a) printf("%d\n",(a))
#define print_b printf("\n")
#define IsNum(x) '0'<=(x)&&(x)<='9'
#define lt dir*2
#define rt dir*2+1

#define maxn 2000010
#define maxm 26
#define inf 1061109567
//const long long inf=1e15;
#define INF 0x3f3f3f3f
#define eps 1e-9
#define E 2.718281828459
const double PI=acos(-1.0);
#define mod 998244353
#define MAXNUM 1000000000

typedef long long ll;
typedef unsigned long long ulld;
ll Abs(ll x) {return (x<0)?-x:x;}
int Read() {char ch;int res=0;while(ch=getchar(),!(IsNum(ch)));while(IsNum(ch)) res=res*10+ch-'0',ch=getchar();return res;}

int main()
{
    //freopen("data.in","r",stdin);
    //freopen("std.out","w",stdout);
    //clock_t st=clock();
    int T;scanfi(T);
    while(T--)
    {
        ll n,ans=-1;
        scanf("%I64d",&n);
        if(n==1) {printf("2\n");continue;}
        int mx=59;ll t2=1,t3=1,t5=1,tmp=0,_tmp;
        FOR(i,0,mx)
        {
            FOR(j,0,mx)
            {
                if(t2*t3<=0) break;
                if(t2*t3>=n) {ans=min(ans,t2*t3);break;}
                FOR(k,0,mx-i)
                {
                    _tmp=tmp;tmp=t2*t3*t5;_tmp=tmp;
                    if(tmp<_tmp) break;             //68719476736 14348907 125
                    if(tmp>=n)
                    {
                        if(ans==-1||ans>tmp) ans=tmp;
                        break;
                    }
                    t5*=5;
                }
                t3*=3;t5=1;
            }
            t2*=2;t3=t5=1;
        }
        printf("%I64d\n",ans);
    }
    //clock_t ed=clock();
    //printf("\n\nTime Used : %.5lf Ms.\n",(double)(ed-st)/CLOCKS_PER_SEC);
    return 0;
}
/*506781279576915968*/
/*507227047723008000*/

 

posted @ 2017-09-11 17:07  CtrlKismet  阅读(144)  评论(0编辑  收藏  举报