anhkiet2507

Số Hoàn Hảo

Apr 22nd, 2021
775
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //C01040 - SỐ HOÀN HẢO
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.    int n,i,tong=0;
  8.    scanf("%d", &n);
  9.    for(i = 1; i<n; ++i)
  10.    {
  11.     if(n%i==0){
  12.         tong = tong + i;
  13.        }
  14.    }
  15.    if (tong == n){
  16.     printf("%s", "1");
  17.    } else {
  18.     printf("%s", "0");
  19.    }
  20.    
  21. return 0;
  22. }
  23.  
  24. //C03009 - SỐ HOÀN HẢO TRONG ĐOẠN
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <math.h>
  28. int SoHoanHao(x){
  29.     int i, tong=0;
  30.     for(i = 1; i<x; ++i){
  31.         if(x%i==0){
  32.             tong = tong + i;
  33.         }
  34.     }
  35.     if (tong == x){
  36.         printf("%d ", x);
  37.     }
  38. }
  39. int main(){
  40.     int a,b,x,j;
  41.     scanf("%d %d", &a, &b);
  42.     if (a<=b){
  43.     for(j = a; j < b; ++j){
  44.         SoHoanHao(j);
  45.     }
  46.     } else {
  47.         for(j = b; j < a; ++j){
  48.         SoHoanHao(j);
  49.     }
  50.     }
  51.    
  52. return 0;
  53. }
  54.  
  55. //C03008 - SỐ HOÀN HẢO NHỎ HƠN N
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58. #include <math.h>
  59. void show (long long n){
  60.     long long sum = 1;
  61.     int i;
  62.     for(i = 2; i <= sqrt(n); i++){
  63.         if(n%i==0){
  64.             sum +=i;
  65.             sum +=(n*1.0)/i;
  66.         }
  67.     }
  68.     if((int)sqrt(n)*(int)sqrt(n)==n)sum = sum - sqrt(n);
  69.     if(sum==n) printf("%d ", n);
  70.  
  71. }
  72. int main(){
  73.     long long n;
  74.     scanf("%lld", &n);
  75.     int i;
  76.     for(i = 1; i<n ; i++){
  77.         show(i);
  78.     }
  79. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×