Page 1 of 1

Posted: Sun Jun 27, 2010 12:21 pm
/*********************************************/
University of Science & Technology Chittagong
(USTC)
CSE 11th Batch
E-mail: gigabyte_yeasin@yahoo.com
/*********************************************/

wht the problem give output -1 for the input 16
the input 996 give the output 662
why ? how ?

### Re: 11728

Posted: Mon Jun 28, 2010 10:55 am
Try to include the name of the problem in the title as well. Something like - 11728 - Alternate Task

Coming back to your problem: According to you, what should be the output for 16?

### Re: 11728 - Alternate Task

Posted: Sat Jul 03, 2010 6:28 pm
/*********************************************/
University of Science & Technology Chittagong
(USTC)
CSE 11th Batch
E-mail: gigabyte_yeasin@yahoo.com
/*********************************************/

Now it is Accepted.
Critical Input:

1
4
12
16
31
102
996
1000
0

Output:

Case 1: 1
Case 2: 3
Case 3: 11
Case 4: -1
Case 5: 25
Case 6: 101
Case 7: 662
Case 8: -1

### Re: 11728 - Alternate Task

Posted: Tue Oct 05, 2010 6:47 pm
why WA????

Code: Select all

``````#include<iostream.h>
#include<math.h>

long int nprime(long int n)
{
long int i,s=0,st=1,p=0,count=0;
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0)
{
n=n/i;
if(p!=i||count%2!=0){p=i;s=s+i;}
else count++;
i=1;st=0;
}
}
if(st==0)
{
//	if(count>=1&&p==n)
//	s=s+n;
//else
if(p!=n||count%2!=0)
s=s+n;
}
return s;
}

int main()
{
long int n,sum=0,m,k,count,signal;
cin>>n;
count=1;
while(n)
{signal=0;
//cin>>n;
m=n;
if(n>1000)
cout<<"Case "<<count<<": "<<"0"<<endl;
else if(m==1)
cout<<"Case "<<count<<": "<<"1"<<endl;
else
{
//if(nprime(n))
//	cout<<"Case "<<count<<": "<<"-1"<<endl;
//else
//	{
for(k=m-1;k>=1;k--)
{
sum=nprime(k);
if(sum+1+k==m)
{signal=k;break;}
}
if(!signal)
cout<<"Case "<<count<<": "<<"-1"<<endl;
else
cout<<"Case "<<count<<": "<<signal<<endl;
//	}
}
count++;
cin>>n;
}
return 0;
}``````

### Re: 11728 - Alternate Task

Posted: Wed Dec 07, 2011 8:02 am
I got TLE for 11728....what's wrong with my code....

#include<stdio.h>
int main()
{
long i,j,k=0,n,s,m=-1,max;
while(scanf("%ld",&n)==1)
{
k++;
if(n==0)
break;
max=-1;
for(i=1;i<=n;i++)
{
s=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
s+=j;
}
}
if(n==s)
{
if(i>max)
{
max=i;
}
}
}
printf("Case %ld: %ld\n",k,max);
}
return 0;
}

### Re: 11728 - Alternate Task

Posted: Sat Jan 14, 2012 12:48 am
With only 1000 possible inputs, you could try and precompute all of the results and store them in an array.