LightOJ 1109 False Ordering Solution

   Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    #include<bits/stdc++.h>
    using namespace std;
    vector<int>v[50];
    int ar[1009];
    int k=1;

    int div(int n)
    {
    int d=1,c=1;

    for(int i=2; i<=n; i++)
    {

    while(n%i==0)
    {
    n/=i;
    c++;
    }
    d*=c;
    c=1;
    }
    return d;
    }

    void crediv()
    {
    for(int i=2; i<=1000; i++)
    {
    int d=div(i);
    v[d].push_back(i);
    }
    for(int i=2;i<=35;i++)
    {
    for(int j=v[i].size()-1;j>=0;j--)
    ar[++k]=v[i][j];
    }

    }

    int main()
    {
    crediv();
    int t;
    cin>>t;
    ar[1]=1;
    for(int i=1;i<=t;i++)
    {
    int n;
    cin>>n;
    printf("Case %d: %d\n",i,ar[n]);
    }
    }

    No comments

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

    Powered by Blogger.