Page 6 of 7

382 Why wrong ans?

Posted: Sat Nov 26, 2011 11:13 am
by rafikamal
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?

Re: 382 Why wrong ans?

Posted: Sat Nov 26, 2011 6:53 pm
by helloneo
1 is not a proper divisor of 1

382 problem on dev c++

Posted: Sat Sep 22, 2012 11:43 am
by vuduclong0309
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;
}

Re: 382 problem on dev c++

Posted: Tue Sep 25, 2012 1:16 am
by brianfry713
Change line 49 to: printf("END OF OUTPUT\n");

Re: 382 problem on dev c++

Posted: Sat Oct 06, 2012 5:57 am
by rafael.sr
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;
}

Re: 382 problem on dev c++

Posted: Sun Oct 07, 2012 7:36 pm
by brianfry713
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: ========

Re: 382 - Perfection - Run Time Error

Posted: Mon Sep 23, 2013 8:58 pm
by raj
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();
	}
}

Re: 382 - Perfection - Why WA ?

Posted: Fri Oct 11, 2013 9:23 pm
by brianfry713
Try a case where the input is on multiple lines, like:

Code: Select all

15 28 6 56 60000
22 496 0

uva 382

Posted: Wed Oct 23, 2013 6:56 pm
by walking_hell
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;
}

Re: uva 382

Posted: Wed Oct 23, 2013 8:27 pm
by brianfry713
There should be an extra space after the digits.

Re: 382 WA

Posted: Sat Nov 02, 2013 8:01 pm
by sadmansobhan

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

Re: 382 WA

Posted: Tue Nov 05, 2013 12:22 am
by brianfry713
Don't read from a file

382 - Perfection getting WA

Posted: Thu Jul 31, 2014 4:31 pm
by NAbdulla
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;
}

Re: 382 - Perfection getting WA

Posted: Thu Jul 31, 2014 10:46 pm
by brianfry713
1 DEFICIENT

Re: 382 - Perfection getting WA

Posted: Fri Aug 01, 2014 5:05 pm
by NAbdulla
Thanks. But now it is "PresentationE".