## 382 - Perfection

Moderator: Board moderators

hsihsiwu
New poster
Posts: 9
Joined: Fri Apr 12, 2002 2:27 am

### 382 - Perfection

If input is "1 0", what is output?

Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany
PERFECTION OUTPUT
1 DEFICIENT
END OF OUTPUT

przygoda
New poster
Posts: 7
Joined: Fri Aug 09, 2002 12:26 pm
Location: Poland

### 382

What is wrong ???

Code: Select all

``````[pascal]

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

begin

writeln('PERFECT OUTPUT');

while not eoln do begin
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]``````

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
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 ....

Sneeze
New poster
Posts: 13
Joined: Thu Jan 30, 2003 4:04 am

### help on q382

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]

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am
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

kurnia w
New poster
Posts: 18
Joined: Fri Dec 06, 2002 3:53 pm
Location: Indonesia
Contact:

### problem 382 WA, Why ??

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]

bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:
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.

Not AC yet AC at last

bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:
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 .
Last edited by bery olivier on Fri Feb 21, 2003 3:08 pm, edited 1 time in total.
Not AC yet AC at last

kurnia w
New poster
Posts: 18
Joined: Fri Dec 06, 2002 3:53 pm
Location: Indonesia
Contact:

Ah...it's help a lot...i got it acc now...
thank's a lot to you bery...

Sarmento
New poster
Posts: 15
Joined: Tue Apr 22, 2003 9:50 pm
Location: Lisboa, Portugal

### 382 - Why am I getting WA?

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.

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)
{
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;
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]
-----------------
Jo

Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm

### 382 - Perfection - Why WA ?

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 ;
}
``````

bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:
Same error as http://acm.uva.es/board/viewtopic.php?t ... hlight=382
1 should be deficient.
Not AC yet AC at last

Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

### 382 Why WA?

#include <iostream.h>
#include <iomanip.h>

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

void main()
{
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;
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;
{
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;
}

Zhao Le
Learning poster
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

### 382 Why WA?

#include <iostream.h>
#include <iomanip.h>

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

void main()
{
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;
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;