Wednesday, 13 April 2016

Solution of URI 1164 :: Perfect Number


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int N, X, a, b, c, d=0;
    scanf("%d", &N);
    for(a=1; a<=N; a++)
    {
        scanf("%d", &X);
        c=X/2; d=0;
        for(b=1; b<=c; b++)
        {
            if(X%b==0)
                d+=b;
        }
        if(d==X)
            printf("%d eh perfeito\n",X);
        else
            printf("%d nao eh perfeito\n",X);
    }
    return 0;
}

3 comments:

  1. #include

    using namespace std;

    int main(){

    int n,i,t,j;
    int soma=0;

    cin>>t;

    for(j=1; j<=t; j++){

    cin>>n;

    for(i=1; i<=n; i++){

    if(n%i==0){

    soma=soma+i;

    }

    }
    soma=soma-n;

    if(soma==n){

    cout<<n<<" eh perfeito"<<endl;
    soma=0;
    }
    else{
    cout<<n<<" nao eh perfeito"<<endl;

    soma=0;
    }

    }

    return 0;


    }


    what's wrong about this code??
    please reply me..

    ReplyDelete
  2. #include
    int main()
    {
    int i,n,x,sum=0,y,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    scanf("%d",&x);

    for(j=1;j<x;j++)
    {
    y=x%j;
    if(y==0)
    sum+=j;
    else
    continue;
    }
    if(x==sum)
    printf("%d eh perfeito\n",x);
    else
    printf("%d nao eh perfeito\n",x);
    sum=0;
    x=0;

    }

    return 0;
    }
    reply....

    ReplyDelete

Note: only a member of this blog may post a comment.