Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
注意,每次查询第N个的时候都重新查询会超时的,虽然1338那道不会,所以还是预先存起来吧#include<iostream> #include<cstdio> #include<queue> using namespace std; priority_queue<long long,vector<long long >, greater<long long > >q; long long a[5]; long long b[6666]; int main() { int n; a[1]=2; a[2]=3; a[3]=5; a[4]=7; b[1]=1; int cnt=1; q.push(2); q.push(3); q.push(5); q.push(7); for(int i=1; i<5842; i++) { long long temp=q.top(); for(int j=1; j<5; j++) q.push(temp*a[j]); b[++cnt]=temp; q.pop(); while(1) { if(temp==q.top()) q.pop(); else break; } } while(scanf("%d",&n)!=EOF && n) { if(n==1) printf("The 1st humble number is 1.\n"); else if(n%10==1 && (n%100)!=11) printf("The %dst humble number is %lld.\n",n,b[n]); else if(n%10==2 && (n%100)!=12) printf("The %dnd humble number is %lld.\n",n,b[n]); else if(n%10==3 && (n%100)!=13) printf("The %drd humble number is %lld.\n",n,b[n]); else printf("The %dth humble number is %lld.\n",n,b[n]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator