rwkj 1303 完數

來源:互聯網
上載者:User

標籤:java   io   for   ar   時間   amp   har   程式   


#include <stdio.h>
int main()
{
int n,i,j,s,k,a[10000];
scanf("%d",&n);

{ s=0; k=0;
for (j=1;j<n;j++)

if (n%j==0) {s+=j;a[k++]=j; }
if(s==n)
for(i=0;i<k;i++) printf("%d ",a[i]);
else printf("no\n");


}
return 0;
}

 

 

 

 

 

 

 

#include <stdio.h>
int main()
{
int n,i,j,s;
scanf("%d",&n);

{ s=0;
for (j=1;j<i;j++)

if (i%j==0) s+=j;
if(s==i) printf("yes\n");
else printf("no\n");


}
return 0;
}

 

 

 

 

 

p89

#include <stdio.h>
int main( )
{
int x,i,m ;
for(x=1 ;x<=1000 ;x++)
{
for(m=0 ,i=1 ;i<=x/2 ; i++)
if(x%i==0) m=m+i ; // if(!(x%i))
if(m==x)
printf("%2d\n",x);
}

return 0;
}

 

 

 


1303

 


C語言:迴圈結構6(完數)
時間限制(普通/Java):1000MS/3000MS 運行記憶體限制:65536KByte
總提交:738 測試通過:539

描述


一個正整數如果恰好等於它的因子之和,這個數就稱為"完數"。 例如,6的因子為1、2、3,而6=1+2+3,因此6是"完數"。

輸入一個正整數n,編程式輸出從2到n間的所有完數。


輸入

一個正整數n。

輸出

從2到n間的所有完數。

範例輸入

50

範例輸出

6
28

 


#include<stdio.h>
int main()
{
int a,j,m,x,n;
x>=2;
x=n;
n<10000;
while (scanf("%d",&x)!=EOF)
{
for(a=2;a<=x;a++)
{
for(m=0,j=1;j<=a/2;j++)
if(!(a%j)) m=m+j;
if(m==a) printf("%d\n",a);

}

}
return 0;
}

 


**********************************************************

 

 

#include <stdio.h>
int main(int argc, char *argv[])
{
int a,j,m,n;

scanf("%d",&n);
for (a=2;a<=n;a++)
{
for ( m=0,j=1;j<=a/2;j++)
if (!(a%j))
m=m+j;
if (m==a)
printf("%d\n",a);
}

 

*******************************************

 

 

#include <stdio.h>
int main()
{
int n,i,j,s;
scanf("%d",&n);
for (i=2;i<=n;i++)
{ s=0;
for (j=1;j<i;j++)

if (i%j==0) s+=j;
if(s==i) printf("%d\n",i);

}
return 0;
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.