382 - Perfection

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

Moderator: Board moderators

rafikamal
New poster
Posts: 2
Joined: Sat Nov 26, 2011 11:06 am

382 Why wrong ans?

Post by rafikamal » Sat Nov 26, 2011 11:13 am

This program runs on my PC nicely and gives desired output but shows WA when submitted:

Code: Select all

#include <stdio.h>

int main()
{
    int i,sum,n;
    printf("PERFECTION OUTPUT\n");
    while(1)
    {
        scanf("%d",&n);
        if(!n) break;
        sum=1;
        for(i=2;i<=n/2;i++)
            if(!(n%i)) sum+=i;

        if(sum==n) printf("%5d  PERFECT\n",n);
        else if(sum<n) printf("%5d  DEFICIENT\n",n);
        else printf("%5d  ABUNDANT\n",n);
    }
    printf("END OF OUTPUT\n");
    return 0;
}
I can't find the problem :( can anyone help me plz?

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 382 Why wrong ans?

Post by helloneo » Sat Nov 26, 2011 6:53 pm

1 is not a proper divisor of 1

vuduclong0309
New poster
Posts: 1
Joined: Sat Sep 22, 2012 11:38 am

382 problem on dev c++

Post by vuduclong0309 » Sat Sep 22, 2012 11:43 am

i have tried all my best but the judge keep saying wa, can u help me fix this below code?

Code: Select all

#include <stdio.h>
int sukk(int m)
{
    int i,isum;
    isum=0;
    for(i=2;i<m;i++)
    {
                     if(m%i!=0) continue;
                     else isum+=i;
    }
    isum+=1;
    return isum;
}

int main()
{
    int i,a[60000],b[60000],k;
    i=0;
    do
    {
    
                         scanf("%d",&a[i]);
                         if(!a[i])
                         {       
                                   k=i;
                                   break;
                         }
                         i+=1;
     }while(i<60000);
     for(i=0;i<=k;i++)
     {
                      b[i]=sukk(a[i]);
     }                 
     printf("PERFECTION OUTPUT\n");
     for(i=0;i<k;i++)
     {
                          printf("%5d  ",a[i]);
                          if(b[i]<a[i]) printf("DEFICIENT\n");
                          else
                          {
                              if(b[i]==a[i])
                              {
                                            if(a[i]=1) printf("DEFICIENT\n");
                                            else printf("PERFECT\n");
                              }
                              else printf("ABUNDANT\n");
                              }
}
     printf("END OF OUTPUT");
     return 0;
}

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

Re: 382 problem on dev c++

Post by brianfry713 » Tue Sep 25, 2012 1:16 am

Change line 49 to: printf("END OF OUTPUT\n");
Check input and AC output for thousands of problems on uDebug!

rafael.sr
New poster
Posts: 1
Joined: Sat Oct 06, 2012 5:52 am

Re: 382 problem on dev c++

Post by rafael.sr » Sat Oct 06, 2012 5:57 am

I'm getting Runtime Error, but in my machine its working, please help!!!

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){  
        int numero;
        bool frase = true;
        do{
            scanf("%d", &numero);
            if (frase){
                printf("PERFECTION OUTPUT\n");
                frase = false;
            }
            if (numero==0){
                printf("END OF OUTPUT\n");
                break;
            }
            int num = numero;
	        int espacos = 5;
            while (num>=1){
            	num=num/10;
            	espacos--;
            }
            char resp[6] = "";
            for (int i=0; i<espacos;i++)
                strcat(resp," ");
            char resp2[6];
            sprintf(resp2, "%s%d", resp, numero);
            int soma=1;
            int limite=numero/2;
            int div=0;
            int cont=0;
            bool abundant=false;
            for(int i=2; i<limite; i++){
                cont++;
                div=numero/i;
                if (numero%i==0) {
                    soma=soma+i+div;
                    if (soma>numero) {printf(strcat(strcat(resp2,"  "),"ABUNDANT\n")); abundant=true; break;}
                    limite=div;
                }
            }
            if (soma<numero || numero==1) printf(strcat(strcat(resp2,"  "),"DEFICIENT\n"));
            else if (!abundant) {printf(strcat(strcat(resp2,"  "),"PERFECT\n")); abundant=false;}
        }while(numero!=0);
        //system("pause");
        return 0;
}

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

Re: 382 problem on dev c++

Post by brianfry713 » Sun Oct 07, 2012 7:36 pm

It looks like you're trying to put too much into resp2

stderr:

*** buffer overflow detected ***: ./prog terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x48)[0xb7559ae8]
/lib/libc.so.6[0xb7557b30]
/lib/libc.so.6[0xb7556dcd]
./prog(__gxx_personality_v0+0x2a0)[0x8048784]
======= Memory map: ========
Check input and AC output for thousands of problems on uDebug!

raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

Re: 382 - Perfection - Run Time Error

Post by raj » Mon Sep 23, 2013 8:58 pm

I am getting "Run time error" Need help!!! :( :( :(

Code: Select all

import java.io.*;
import java.util.*;
public class Main{  
	  public static long sumDiv(long N) {
		  long sqrt = (long)Math.sqrt(N);
		  long sum = 0;
		  for(long c = 1;c<=sqrt;c++){
			  if(N%c==0){
				  long d = N/c;
				  if(c==d){
					  sum = sum + c;
					  break;
				  }
				  sum = sum + c + d;
			  }
		  }
		  return sum-N;	  
	  }
	public static void main(String[] args)throws IOException {
		BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader k = new BufferedReader(new FileReader("D:/Uva-input.txt.txt"));
		PrintWriter z = new PrintWriter(System.out);
		z.println("PERFECTION OUTPUT");
		String line;
		while((line = k.readLine())!=null){
			StringTokenizer s = new StringTokenizer(line);
			long n;
			while((n = Long.valueOf(s.nextToken()))!=0){
				long ans = sumDiv(n);
				if(ans == n){
					z.printf("%5s",n); 
					z.println("  PERFECT");
				}
				else if(ans < n){
					z.printf("%5s",n);
					z.println("  DEFICIENT");
				}
				else{
					z.printf("%5s",n);
					z.println("  ABUNDANT");
				}
			}
		}
		z.println("END OF OUTPUT");
		z.flush();
	}
}

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

Re: 382 - Perfection - Why WA ?

Post by brianfry713 » Fri Oct 11, 2013 9:23 pm

Try a case where the input is on multiple lines, like:

Code: Select all

15 28 6 56 60000
22 496 0
Check input and AC output for thousands of problems on uDebug!

walking_hell
New poster
Posts: 14
Joined: Tue Sep 24, 2013 4:35 pm

uva 382

Post by walking_hell » Wed Oct 23, 2013 6:56 pm

why PE ????

Code: Select all

#include<stdio.h>
int func(int x)
{
    int mid=x/2,count,sum=0;

    for(count=1;count<=mid;count++)
    {
        if(x%count==0)
        sum=sum+count;

    }

    if(sum==x)
    return 0;
    else if(sum>x)
    return 1;
    else
    return 2;


}
int main()
{

    int num,arr[100],nums[100],c=0;

    while(scanf("%d",&num)==1 && num!=0)
    {

        arr[c]=func(num);
        nums[c++]=num;

    }
    printf("PERFECTION OUTPUT\n");
    for(num=0;num<c;num++)
    {
        if(arr[num]==0)
        printf("%5d PERFECT\n",nums[num]);
        else if(arr[num]==1)
        printf("%5d ABUNDANT\n",nums[num]);
        else
        printf("%5d DEFICIENT\n",nums[num]);
    }


    printf("END OF OUTPUT\n");


    return 0;
}

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

Re: uva 382

Post by brianfry713 » Wed Oct 23, 2013 8:27 pm

There should be an extra space after the digits.
Check input and AC output for thousands of problems on uDebug!

sadmansobhan
New poster
Posts: 16
Joined: Thu Oct 10, 2013 8:06 am

Re: 382 WA

Post by sadmansobhan » Sat Nov 02, 2013 8:01 pm

Code: Select all

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    freopen("in.txt", "r", stdin);
    int a;
    cout << "PERFECTION OUTPUT" << endl;
    while((cin>>a)!=0)
    {
        if(a==0)
        {
            break;
        }
        else
            {
                int n=0;
                for(int i=1;i<=a/2;i++)
                {
                    if(a%i==0)
                        n=n+i;
                }
                printf("%5d",a);
                if(a==n)
                    cout << "PERFECT";
                else if(a>n)
                    cout << "DEFICIENT";
                else
                    cout << "ABUNDANT";
                cout << endl;
            }
    }
    cout << "END OF OUTPUT" << endl;
    return 0;
}
I get WA why.plz help

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

Re: 382 WA

Post by brianfry713 » Tue Nov 05, 2013 12:22 am

Don't read from a file
Check input and AC output for thousands of problems on uDebug!

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

382 - Perfection getting WA

Post by NAbdulla » Thu Jul 31, 2014 4:31 pm

Please help me to find my faults:
My code

#include <stdio.h>
int main()
{
long int n, d, sum, nums[105], i, j;
i = 0;
while(scanf("%ld", &n)){
nums = n;
i++;
if(n == 0) break;
}
printf("PERFECTION OUTPUT\n");
j = 0;
while(j < i){
n = nums[j];
sum = 1;
d = 2;
while(d <= n/2){
if(n % d == 0){
sum = sum + d;
}
d++;
}
if(n == 0){
printf("END OF OUTPUT\n");
}
else if(sum == n){
printf("%5ld PERFECT\n", n);
}
else if(sum < n){
printf("%5ld DEFICIENT\n", n);
}
else if(sum > n){
printf("%5ld ABUNDANT\n", n);
}
j++;
}
return 0;
}

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

Re: 382 - Perfection getting WA

Post by brianfry713 » Thu Jul 31, 2014 10:46 pm

1 DEFICIENT
Check input and AC output for thousands of problems on uDebug!

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

Re: 382 - Perfection getting WA

Post by NAbdulla » Fri Aug 01, 2014 5:05 pm

Thanks. But now it is "PresentationE".

Post Reply

Return to “Volume 3 (300-399)”