Advertisement
nguyenhappy92

Tính tích tất cả ước số của số nguyên dương n.

Sep 18th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. // Tinh tong cac uoc so nguyen duong
  2. // khai bao ham thu vien
  3.  
  4. #include<stdio.h>
  5. #include<conio.h>
  6. int soNT(int n);
  7. void main()
  8. {
  9. int n;
  10. scanf("%d",&n);
  11. long tong=1;
  12. if(n==0)
  13. {
  14. printf("0");
  15. }
  16. else
  17. {
  18. for(int i=1;i<=n;i++)
  19. {
  20. if(n%i==0)
  21. if(soNT(i)==1)
  22. {
  23. tong=tong+i;
  24. }
  25. }
  26. printf("%ld",tong);
  27. }
  28. }
  29. int soNT(int n)
  30. {
  31. int dem =0;
  32. for(int i=1;i<=n;i++)
  33. {
  34. if(n%i==0)
  35. dem++;
  36. }
  37. if(dem==2)
  38. return 1; // so nguyen to
  39. else
  40. return 0; // khong la so nguyen to
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement