Advertisement
bappi2097

N - False Ordering

Sep 12th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int ll;
  4. struct Node
  5. {
  6.     int num;
  7.     int cnt=0;
  8. };
  9. vector<Node>divisors(1000);
  10. bool myfunc(Node x,Node y)
  11. {
  12.     if(x.cnt<y.cnt)return true;
  13.     else if(x.cnt==y.cnt )return x.num>y.num;
  14.     else return false;
  15.  
  16. }
  17. void Divisor(int n)
  18. {
  19.     for(int i=1;i<=n;i++)divisors[i-1].num=i;
  20.     for(int i=1;i<=n;i++)for(int j=i;j<=n;j+=i)divisors[j-1].cnt++;
  21.     sort(divisors.begin(),divisors.end(),myfunc);
  22.     return;
  23. }
  24. int main()
  25. {
  26.     ios_base::sync_with_stdio(false);
  27.     cin.tie(NULL);
  28.     #ifndef ONLINE_JUDGE
  29.     freopen("input.cpp","r",stdin);
  30.     freopen("output.cpp","w",stdout);
  31.     #endif // ONLINE_JUDGE
  32.     Divisor(1000);
  33.     int t;
  34.     cin>>t;
  35.     for(int l=1;l<=t;l++)
  36.     {
  37.         int n;
  38.         cin>>n;
  39.         cout<<"Case "<<l<<": "<<divisors[n-1].num<<endl;//<<' '<<divisors[n-1].cnt<<endl;
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement