51nod 1010 contains only the number of factors 2 3 5 (table + sort + two)

Source: Internet
Author: User

1010 contains only the number of factor 2 3 5 Base time limit:1 seconds space limit:131072 KB score: Difficulty:2-level algorithm problem The collection focuses on removing the factor that concerns K only contains 2 3 5. The first 10 numbers that meet the criteria are: 2,3,4,5,6,8,9,10,12,15. All such k make up a sequence s, and now give a number n, to find the smallest number of >= given in S. For example: n = the minimum number of >= 13 in 13,s is 15, so output 15. Input
Line 1th: A number t that represents the number of numbers that are later used as input tests. (1 <= T <= 10000) 2-t + 1 lines: 1 numbers per line n (1 <= n <= 10^18)
Output
A total of T-lines, 1 digits per line, and the smallest of the output >= n contains only the number of factors 2 3 5.
Input example
518133577
Output example
28153680

1#include <iostream>2#include <algorithm>3 using namespacestd;4typedefLong Longll;5 Constll n=1e18+ +;6 Constll maxn=1e6+Ten;7 intT;8 ll A[MAXN];9 intD;Ten voidInit () One { AD=0; -      for(LL i=1; i<n;i*=2) -          for(LL j=1; j*i<n;j*=3) the          for(LL k=1; i*j*k<n;k*=5) -a[d++]=i*j*K; -a[0]=-1; -Sort (a,a+d); + } - intMain () + { AIos::sync_with_stdio (false); at init (); -Cin>>T; -      while(t--) -     { - ll tmp; -Cin>>tmp; inll Pos=lower_bound (a,a+d,tmp)-A; -cout<<a[pos]<<Endl; to     } +     return 0; -}
View Code

51nod 1010 contains only the number of factors 2 3 5 (table + sort + two)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.