11728 - Alternate Task

All about problems in Volume 117. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
yeasin_acm_solver
New poster
Posts: 11
Joined: Wed Jun 09, 2010 2:30 pm
Location: University Of Science & Technology Chittagong (USTC) Bangladesh

11728 - Alternate Task

Post by yeasin_acm_solver » Sun Jun 27, 2010 12:21 pm

/*********************************************/
Muhammad Yeasin
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 ?

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 11728

Post by sohel » 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?

yeasin_acm_solver
New poster
Posts: 11
Joined: Wed Jun 09, 2010 2:30 pm
Location: University Of Science & Technology Chittagong (USTC) Bangladesh

Re: 11728 - Alternate Task

Post by yeasin_acm_solver » Sat Jul 03, 2010 6:28 pm

/*********************************************/
Muhammad Yeasin
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

Mizanur Rahman(IUK)
New poster
Posts: 12
Joined: Wed Aug 18, 2010 12:07 pm

Re: 11728 - Alternate Task

Post by Mizanur Rahman(IUK) » 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;
}

happy_dayz
New poster
Posts: 1
Joined: Mon Dec 05, 2011 2:36 pm

Re: 11728 - Alternate Task

Post by happy_dayz » 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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11728 - Alternate Task

Post by brianfry713 » 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.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 117 (11700-11799)”