51Nod 1010 contains only the number of factor 2 3 5 Label:none

Source: Internet
Author: User

The factor of K contains only 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
Code
1#include <iostream>2#include <cstdlib>3#include <cstring>4#include <cstdio>5#include <algorithm>6#include <queue>7#include <map>8#include <vector>9 #definell Long LongTen #defineINF 1500000000000000000 One using namespacestd;  A  - structcmp{BOOL operator(ll A,ll b) {returnA>b;}}; -Priority_queue<ll,vector<ll>,cmp>Q; theMap<ll,int>m; -  -ll a[1000005],m,p; -  + voidInit_ () { -Q.push (1); +      while(Q.top () <INF) { All x=q.top (); Q.pop (); ata[p++]=x; -         if(!m.count (2*x)) {Q.push (2*X); m[2*x]=1;} -         if(!m.count (3*x)) {Q.push (3*X); m[3*x]=1;} -         if(!m.count (5*x)) {Q.push (5*X); m[5*x]=1;} -     } -      in     //cout<<p<<endl; -scanf"%d",&M); to } +  - voidWork () { the      while(m--){ * ll X; $scanf"%lld",&x);Panax Notoginseng          -printf"%lld\n", *lower_bound (A +1, a+p+1, x)); the     } + } A  the intMain () { + //freopen ("01.in", "R", stdin); -      $ Init_ (); $ Work (); -      -Fclose (stdin); fclose (stdout);return 0; the}

Make a priority queue, generate larger numbers with existing numbers

Map de-weight, lower_bound two-point acceleration

INF less hit a 0 and unhappy

Time is OK, I think the main question is the time, because the counter bacteria that the number in the data range only 1w+

51Nod 1010 contains only the number of factor 2 3 5 Label:none

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.