Số gần hoàn hảo

View as PDF

Submit solution

Points: 0.01 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: GHH.INP
Output: GHH.OUT

Author:
Problem type
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

Một số nguyên dương ~A~ được gọi là số "gần hoàn hảo" nếu thỏa mãn điều kiện: ~2 \times A \le K~, với ~K~ là tổng các ước số của ~A~.

Ví dụ: ~12~ là một số "gần hoàn hảo" vì ~2 \times 12 \lt 1 + 2 + 3 + 4 + 6 + 12~.

Yêu cầu: Cho một dãy số nguyên dương, hãy in ra các số "gần hoàn hảo".

Input

Vào từ file GHH.INP có cấu trúc như sau:

  • Dòng đầu tiên chứa số nguyên dương ~N~ (~0 \lt N \le 10^4~).

  • ~N~ dòng tiếp theo, mỗi dòng là một số nguyên dương có giá trị không vượt quá ~10^6~.

Output

Ghi ra file GHH.OUT gồm:

  • Dòng đầu tiên ghi số lượng số "gần hoàn hảo".

  • Các dòng tiếp theo, mỗi dòng ghi một số "gần hoàn hảo", số gặp trước thì viết trước.

Sample Input 1

5
8
16
12
6
7

Sample Output 1

2
12
6

Comments

Please read the guidelines before commenting.



  • 0
    soncris779  commented on Nov. 18, 2025, 2:30 a.m.

    include<bits/stdc++.h>

    include<algorithm>

    include<vector>

    include<unordered_map>

    include<set>

    define pb push_back

    define endl "\n"

    define ll long long

    define siu cin.tie(nullptr)->syncwithstdio(false);

    using namespace std; ll check(ll n) { ll res = 1;

    for (ll p = 2; p * p <= n; p++) {
        if (n % p == 0) {
            ll sumP = 1;
            ll powP = 1;
            while (n % p == 0) {
                n /= p;
                powP *= p;
                sumP += powP;
            }
            res *= sumP;
        }
    }
    
    if (n > 1) res *= (1 + n); 
    
    return res;
    

    }

    void solve() { ll n; cin >> n; vector<ll>a(n); vector<ll>v; for(ll &x : a) { cin >> x; if(x * 2 <= check(x)) { v.pb(x); } } cout << v.size()<<endl; for(ll x : v) { cout << x <<endl; } } int main() { //freopen("GHH.INP","r",stdin); //freopen("GHH.OUT","w",stdout); siu; solve(); return 0; }


  • 0
    tranhongminh21082007  commented on Nov. 18, 2025, 12:52 a.m.
    #include <bits/stdc++.h>
    using namespace std;
    
    long long sumDiv(long long n) {
        long long s = 0;
        for(long long i = 1; i * i <= n; i++) {
            if(n % i == 0) {
                s += i;
                if(i * i != n) s += n / i;
            }
        }
        return s;
    }
    int main() {
        int N;
        cin >> N;
        vector&lt;long long> a(N), ans;
        for(int i = 0; i < N; i++) cin >> a[i];
    
        for(int i = 0; i < N; i++) {
            long long n = a[i];
            if(sumDiv(n) == 2*n - 1) {
                ans.push_back(n);
            }
        }
        cout << endl;
        cout << ans.size() << "\n";
        for(long long x : ans) cout << x << "\n";
    
        return 0;
    }
    

  • -2
    mhieu_uu  commented on Sept. 28, 2025, 2:22 p.m. edited

    hay


  • -3
    hahuu5972  commented on Sept. 23, 2025, 2:50 p.m. edited

    jjj


  • -6
    THPTHD_Hieu  commented on May 12, 2025, 7:32 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -7
      RussVN123  commented on May 14, 2025, 8:04 a.m.

      This comment is hidden due to too much negative feedback. Show it anyway.


      • -6
        THPTHD_Hieu  commented on May 15, 2025, 1:35 a.m.

        This comment is hidden due to too much negative feedback. Show it anyway.


  • -12
    hvycutis1tg  commented on May 9, 2025, 11:05 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.