Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
| discuss443 - | Accepted | C++11 | 0.000 | 0.000 | 945 | 1 mins ago |
Suggest:
- Use set data struct to create humble numbers
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
string s;
set<int> humble;
vector<int> a(1,0);
int last = 2000000000;
void f(int x, int n){
if (x*n <= last) humble.insert(x*n);
}
void f1(){
humble.insert(1);
for(auto x:humble) f(x,2), f(x,3), f(x,5), f(x,7);
for(auto x:humble) a.push_back(x);
}
void f2(){
while(cin >> n && n){
s="th";
if(n%100>10 && n%100<20) s="th";
else if (n%10==1) s="st";
else if (n%10==2) s="nd";
else if (n%10==3) s="rd";
cout<<"The "<<n<<s<<" humble number is "<<a[n]<<".\n";
}
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
f1();
f2();
}
No comments:
Post a Comment