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

    RESTful APIs with CRUD Operations in Laravel 12| (2025)

      RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

    Powered by Blogger.