Page 1 of 7

382 - Perfection

Posted: Thu Apr 25, 2002 2:28 pm
by hsihsiwu
If input is "1 0", what is output?

Thanks for your help.

Posted: Thu Apr 25, 2002 7:10 pm
by Adrian Kuegel
PERFECTION OUTPUT
1 DEFICIENT
END OF OUTPUT

382

Posted: Fri Aug 09, 2002 12:36 pm
by przygoda
Please help me !!!
What is wrong ???
:evil:

Code: Select all

[pascal]

program glupii;
var
 liczba,z,sumka,la,i,pom,u:longint;


begin

 writeln('PERFECT OUTPUT');

  while not eoln do begin
   read(liczba);
   if liczba=1 then begin
    writeln('    ',1,'  DEFICIENT');
     continue;
      end;
   sumka:=0;
   if liczba=0 then break;
   pom:=(liczba div 2 ) ;
   for i:=1 to pom do
    if liczba mod i = 0 then sumka:=sumka+i;

    la:=1;
   for z:=1 to 6 do begin
    la:=la*10;
     if la > liczba then begin
      if la=100000 then continue
      else
       for u:=z+1 to  5 do write(' ');
       break;
      end;
     end;

   write(liczba,'  ');

   if sumka < liczba then begin write('DEFICIENT');writeln;continue;end;
   if sumka = liczba then write('PERFECT')
   else
   write('ABUNDANT');
   writeln;
 end;
 writeln('END OF OUTPUT');
end.



[/pascal]

Posted: Fri Aug 09, 2002 2:20 pm
by Dominik Michniewski
if sumka < liczba then begin write('DEFICIENT');writeln;continue;end;
if sumka = liczba then write('PERFECT')
else
write('ABUNDANT');

I'm not really good in free Pascal, but I think that it's incorrect (this 3 lines)
What's about sumka = 3 and liczba = 4 ? I think, that you forgot one else ....

help on q382

Posted: Tue Feb 04, 2003 4:48 am
by Sneeze
I got a WA. Can anyone help me figure out why?

[cpp]#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

void main()
{
long input, sum, factor, factor2, sq;
cout << "PERFECTION OUTPUT" << endl;
cin >> input;
while(input)
{
sum=1, factor=2;
sq=(long)sqrt(input);
if((sq+1)*(sq+1)<=input)
sq++;
while(factor<=sq)
{
if(!(input%factor))
{
factor2=input/factor;
if(factor2>factor)
sum+=factor2;
sum+=factor;
}
factor++;
}
if(sum<input)
cout << setw(5) << setiosflags(ios::right) << input << " DEFICIENT" << endl;
else if(sum>input)
cout << setw(5) << setiosflags(ios::right) << input << " ABUNDANT" << endl;
else
cout << setw(5) << setiosflags(ios::right) << input << " PERFECT" << endl;
cin >> input;
}
cout << "END OF OUTPUT" << endl;
}[/cpp]

Posted: Sat Feb 15, 2003 8:30 am
by Red Scorpion
Try This test cases:
Input:
1 3 4 28 99 29 39999 60000 2 9 1 5 799 800
10 20190 34568 59999 54999 3421 10213
9912 6 0

Output:
PERFECTION OUTPUT
1 DEFICIENT
3 DEFICIENT
4 DEFICIENT
28 PERFECT
99 DEFICIENT
29 DEFICIENT
39999 DEFICIENT
60000 ABUNDANT
2 DEFICIENT
9 DEFICIENT
1 DEFICIENT
5 DEFICIENT
799 DEFICIENT
800 ABUNDANT
10 DEFICIENT
20190 ABUNDANT
34568 DEFICIENT
59999 DEFICIENT
54999 DEFICIENT
3421 DEFICIENT
10213 DEFICIENT
9912 ABUNDANT
6 PERFECT
END OF OUTPUT :lol:

problem 382 WA, Why ??

Posted: Thu Feb 20, 2003 4:09 pm
by kurnia w
What's wrong with this code?. look's correct "to me"...
[c]#include<stdio.h>

void main() {
long int i,sum,flag=1;
long int n;
int x,y;
while(scanf("%ld",&n)!=EOF) {
if(flag==1) { printf("PERFECTION OUTPUT\n"); flag=0; }
if(n==0) { printf("END OF OUTPUT\n\n"); flag=1; break; }
sum=1;
for(i=2; i<=n/2; i++) {
if(n%i==0) sum+=i;
}
if(sum<n) printf("%5ld DEFICIENT\n",n);
if(sum==n) printf("%5ld PERFECT\n",n);
if(sum>n) printf("%5ld ABUNDANT\n",n);
}
}
[/c]

Posted: Thu Feb 20, 2003 5:51 pm
by bery olivier
You didn't say what doesn't work. If it's an input problem, I guess that this :
[c]
while(scanf("%ld",&n)!=EOF)
[/c]
should be replaced by this :
[c]
while(scanf("%ld",&n)==1)
or
while(scanf("%ld",&n)!=0)
or
while(scanf("%ld",&n)>0)
or
while(scanf("%ld",&n))
[/c]
Cause scanf return the number of inputs it was able to read.

You can also remove your flag by putting your print before your while.

Posted: Thu Feb 20, 2003 6:07 pm
by bery olivier
I tried to send your source and I got WA. For 1 it gives me "PERFECT" but in this case |c|=1. Try this
[c]sum=0;
for(i=1; i<=n/2; i++) [/c]
It should be Acc.


You should remove the second \n after END OF OUTPOUT as well cause it'll give P.E.


Hope that it helps :wink: .

Posted: Thu Feb 20, 2003 6:48 pm
by kurnia w
:D
Ah...it's help a lot...i got it acc now...
thank's a lot to you bery...

382 - Why am I getting WA?

Posted: Wed Apr 23, 2003 1:09 pm
by Sarmento
Can anyone help out with this one. My prog seems to be working perfectly, but I still get WA...
The Java support of the online-judge, should be improving ASAP.

Thanks in advance,

joao sarmento

[java]
// @JUDGE_ID: 30701AE 382 Java
import java.io.*;
import java.util.*;

class Main
{
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}

if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}

public String str(int i){
String ret = " " + i;
ret = ret.substring(ret.length()-5);
return ret;
}

public static void main (String args[]) // entry point from OS
{
Main myWork = new Main(); // create a dinamic instance
myWork.Begin(); // the true entry point
}

void Begin(){
String str;
StringTokenizer str2;
int a, sum = 0;
str = Main.ReadLn(255);
str2 = new StringTokenizer(str);
a = Integer.parseInt(str2.nextToken());
System.out.println("PERFECTION OUTPUT");
while (a != 0){
for (int i = 1; i <= a/2; i++) {
if (a%i == 0)
sum+=i;
}
if (sum == a)
System.out.println(str(a) + " PERFECT");
if (sum > a)
System.out.println(str(a) + " ABUNDANT");
if (sum < a)
System.out.println(str(a) + " DEFICIENT");
a = Integer.parseInt(str2.nextToken());
sum = 0;
}
System.out.println("END OF OUTPUT");
}
}[/java]

382 - Perfection - Why WA ?

Posted: Wed Apr 30, 2003 6:29 am
by Almost Human
any suggestion ? please help !

code :

Code: Select all

#include <math.h>
#include <stdio.h>

int main ( )
{
  unsigned ToBeTest , i , j ;
  unsigned long counter ;
  double limit ;

/*  freopen ( "382.in" , "r" , stdin ) ;
  freopen ( "382.out" , "w" , stdout ) ;*/

  printf ( "PERFECTION OUTPUT\n" ) ;

  while ( 1 )
  {
	 scanf ( "%u" , &ToBeTest ) ;

	 if ( !ToBeTest ) break ;

	 for ( i = 2 , counter = 1 , limit = floor ( sqrt ( ToBeTest ) ) ; i <= limit ; i ++ )
	 {
		if ( ToBeTest % i == 0 )
		{
		  counter += i ; if ( ToBeTest / i != i ) counter += ( ToBeTest / i ) ;
		}
	 }

	 if ( counter == ToBeTest ) printf ( "%5u  PERFECT\n" , ToBeTest ) ;
	 else if ( counter > ToBeTest ) printf ( "%5u  ABUNDANT\n" , ToBeTest ) ;
	 else printf ( "%5u  DEFICIENT\n" , ToBeTest ) ;
  }

  printf ( "END OF OUTPUT\n" ) ;

  return 0 ;
}

Posted: Wed Apr 30, 2003 10:10 am
by bery olivier
Same error as http://acm.uva.es/board/viewtopic.php?t ... hlight=382
1 should be deficient.

382 Why WA?

Posted: Fri May 09, 2003 1:50 am
by Zhao Le
#include <iostream.h>
#include <iomanip.h>

struct S
{
long n;
int tag;
S *next;
};

void main()
{
S *p,*q,*head=NULL;
long n;
while(1)
{
cin>>n;
if(n==0) break;
long sum=0,i=n-1;
while(i)
{
if(n%i==0) sum+=i;
i--;
}
p=new S;
if(head==NULL) head=p;
else q->next=p;
p->n=n;
if(n==sum) p->tag=0;
else if(n>sum) p->tag=-1;
else p->tag=1;
p->next=NULL;
q=p;
}
cout<<"PERFECTION OUTPUT"<<endl;
for(p=head;p->next;p=p->next)
{
cout<<setw(5);
if(p->tag==0) cout<<p->n<<" PERFECT"<<endl;
else if(p->tag==-1) cout<<p->n<<" DEFICIENT"<<endl;
else cout<<p->n<<" ABUNDANT"<<endl;
}
cout<<"END OF OUTPUT"<<endl;
}

382 Why WA?

Posted: Fri May 09, 2003 1:52 am
by Zhao Le
#include <iostream.h>
#include <iomanip.h>

struct S
{
long n;
int tag;
S *next;
};

void main()
{
S *p,*q,*head=NULL;
long n;
while(1)
{
cin>>n;
if(n==0) break;
long sum=0,i=n-1;
while(i)
{
if(n%i==0) sum+=i;
i--;
}
p=new S;
if(head==NULL) head=p;
else q->next=p;
p->n=n;
if(n==sum) p->tag=0;
else if(n>sum) p->tag=-1;
else p->tag=1;
p->next=NULL;
q=p;
}
cout<<"PERFECTION OUTPUT"<<endl;
for(p=head;p->next;p=p->next)
{
cout<<setw(5);
if(p->tag==0) cout<<p->n<<" PERFECT"<<endl;
else if(p->tag==-1) cout<<p->n<<" DEFICIENT"<<endl;
else cout<<p->n<<" ABUNDANT"<<endl;
}
cout<<"END OF OUTPUT"<<endl;
}