... HAVE U TRIED .... AT LEAST 3 TIMES ... OK U CAN SEE THIS ...

Sunday, January 12, 2014

UVA-11728 :: Alternate Task

//Problem link>>http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2828

#include <bits/stdc++.h>
using namespace std ;

int go(int n)
{
     int x=1 , i ;
        for (i=n ; i>1 ; i--)
        {
            if (n%i==0)
            {
                x=x+i ;
            }
        }

        return x ;
}

int main ()
{
    int i , s ,n ,cas=1 ;
    while (cin>>s && s !=0)
    {
       for (i=s ; i>=0 ; i--)
       {
           if (go(i)==s) {cout<<"Case "<<cas++<<": "<<i<<endl ; break ;}
           else if (i==0) cout<<"Case "<<cas++<<": -1"<<endl ;
       }

    }

    return 0 ;
}

No comments:

Post a Comment