/* Bismillahir Rahmanir Rahim
Saving number of divisor for every number and
sorting using structure.
*/
#include<bits/stdc++.h>
using namespace std;
int t, n, i, j, cs=1;
struct all{
int num;
int ds;
}one[1001];
bool comp(all f, all s){ // sort of structure
if(f.ds==s.ds) return f.num>s.num;
else return f.ds<s.ds;
}
void cal(){ // main calculation for all numbers
for(i=1; i<=1000; i++){
one[i].num=i;
one[i].ds=1;
}
for(i=1; i<=500; i++){
for(j=2*i; j<=1000; j+=i){
one[j].ds=one[j].ds+1;
}
}
}
int main(){
cal();
sort(one, one+1001, comp);
cin>>t;
while(t--){
cin>>n;
cout<<"Case "<<cs++<<": "<<one[n].num<<endl;
}
return 0;
}
|
Wednesday, March 22, 2017
Solution of Light OJ 1109 - False Ordering
Subscribe to:
Post Comments (Atom)
-
#include<bits/stdc++.h> #define ll long long using namespace std ; ll n , k , t_case ; ll bigmod ( ll b , ll p , ll m...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3...
No comments:
Post a Comment