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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

    Powered by Blogger.