UVa 12004 - Bubble Sort Solution

#include <iostream>
using namespace std;
int n,st,en;
int main(){
    ios::sync_with_stdio(0);
    int t,i=0;
    cin>>t;
    while(t--){
        long long int n;
        cin>>n;
        cout<<"Case "<<++i<<": ";
        if(n%4==0||n%4==1)
            cout<<(n*(n-1))/4<<endl;
        else{
            long long int x1=n,x2=n-1,x3=4;
            if(n%2==0)
                x1/=2,x3=2;
            if((n-1)%2==0)
                x2/=2,x3=2;
            cout<<(x1*x2)<<"/"<<x3<<endl;
        }
    }
}

Comments