Số hoàn thiện là các số nguyên dương n sao cho:
n = s(n),
trong đó, s(n) là hàm tổng giới hạn các ước của n (nghĩa là tổng các ước chính thức của n), hoặc:
σ(n) = 2n,
trong đó, σ(n) là hàm tổng các ước của n (nghĩa là tổng các ước của n, bao gồm cả n).
nguồn : http://vi.wikipedia.org
// bai9.cpp : Defines the entry point for the console application.
//
// code Dung NV
#include"stdafx.h"
#include<conio.h>
#include<stdio.h>
intktsht(int n)
{
int i;
intk=0;
for(i=2;i<n;i++) if(n%i==0)
{
k+=i;
if(k>n) return 0;
}
if(n==k) return 1; elsereturn 0;
}
int_tmain(int argc, _TCHAR* argv[])
{
intn;
printf("\nNhap N= ");
scanf("%d",&n);
if(ktsht(n)) printf("\n%5d La so hoan thien",n);
elseprintf("\n%5d khong phai la so hoan thien",n);
getch();
return0;
}
No comments:
Post a Comment