THPTTD_93 - Số Nasty

Xem dạng PDF

Gửi bài giải


Điểm: 6,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: bai3.inp
Output: bai3.out

Tác giả:
Dạng bài
Ngôn ngữ cho phép
C, C#, C++, Go, Java, JavaScript, Kotlin, Pascal, Perl, PHP, PyPy, Python, Ruby, Rust, Scratch, Swift

Trong trường hợp đề bài hiển thị không chính xác, bạn có thể tải đề bài tại đây: Đề bài


Bình luận

Please read the guidelines before commenting.



  • 1
    mducc  đã bình luận lúc 18, Tháng 6, 2026, 13:17

    sao ae làm phức tạp vậy :D

    ta có thể làm như sau: với mỗi truy vấn ta duyệt i đến ~\sqrt{x}~ và mỗi lần ~x~ chia hết cho ~i~ thì dùng map lưu lại 2 giá trị ~i~ ~+~ ~\frac{x}{i}~ và ~\frac{x}{i}~ ~-~ ~i~

    sau đó check xem trong map có giá trị nào xuất hiện hơn 1 lần là được

    Code tham khảo (C++)

    #include <bits/stdc++.h>
    
    #define FOR(i, A, B) for(int i = (A), (_B) = (B); i <= (_B); ++i)
    
    using namespace std;
    
    int main(void) {
        freopen("bai3.inp", "r", stdin);
        freopen("bai3.out", "w", stdout);
        ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
        int tt;
        cin>>tt;
        while(tt--) {
            int n;
            cin>>n;
            int x = sqrt(n);
            map<int, int> mp;
            FOR(i, 1, x) if(n % i == 0) mp[i + n/i]++, mp[n/i-i]++;
            bool ok = false;
            for(auto &p : mp) if(p.second >= 2) {
                ok = true;
                break;
            }
            cout<<ok<<'\n';
        }
        return 0;
    }
    

  • 0
    ToiNhoDuongThanhThao  đã bình luận lúc 11, Tháng 6, 2026, 4:11

    include <iostream>

    include <vector>

    include <cmath>

    include <fstream>

    using namespace std;

    bool ktnasty(int n) { vector<int> u; for (int i = 1; i * i <= n; ++i) { if (n % i == 0) { u.pushback(i); if (i * i != n) u.push_back(n / i); } } int sz = u.size(); for (int i = 0; i < sz; ++i) { for (int j = i + 1; j < sz; ++j) { int a = u[i], b = u[j]; int c = n / a, d = n / b; if (abs(a - b) == (c + d) || abs(a - c) == (b + d) || abs(a - d) == (b + c)) return true; } } return false; }

    int main() { ifstream fi("bai3.inp"); ofstream fo("bai3.out"); int n, x; if (!(fi >> n)) return 0; while (n--) { fi >> x; fo << kt_nasty(x) << endl; } fi.close(); fo.close(); return 0; }


  • 0
    ToiNhoDuongThanhThao  đã bình luận lúc 11, Tháng 6, 2026, 4:10

    Tham khảo

    include <iostream>

    include <vector>

    include <cmath>

    include <fstream>

    using namespace std;

    bool ktnasty(int n) { vector<int> u; for (int i = 1; i * i <= n; ++i) { if (n % i == 0) { u.pushback(i); if (i * i != n) u.push_back(n / i); } } int sz = u.size(); for (int i = 0; i < sz; ++i) { for (int j = i + 1; j < sz; ++j) { int a = u[i], b = u[j]; int c = n / a, d = n / b; if (abs(a - b) == (c + d) || abs(a - c) == (b + d) || abs(a - d) == (b + c)) return true; } } return false; }

    int main() { ifstream fi("bai3.inp"); ofstream fo("bai3.out"); int n, x; if (!(fi >> n)) return 0; while (n--) { fi >> x; fo << kt_nasty(x) << endl; } fi.close(); fo.close(); return 0; }


  • 0
    phucan1402  đã bình luận lúc 1, Tháng 11, 2025, 12:09

    tham khảo nha mn

    #include <iostream>
    #include <climits>
    #include <algorithm>
    #include <cmath>
    #include <vector>
    using namespace std;
    using ll = long long;
    const int maxn = 1e6;
    ll a[maxn + 5];
    void AC() {
        int n; cin >> n;
        vector<bool> mark(2005, 0);
        vector<pair<int,int>> thuaso;
        for(int i = 1; i <= sqrt(n); i++) {
            if(n % i == 0) {
                thuaso.push_back({i,n/i});
            }
        }
        for(auto it : thuaso) {
            int hieu = abs(it.first-it.second);
            int tong = it.first + it.second;
            mark[tong] = true;
        }
        for(auto it : thuaso) {
            int hieu = abs(it.first-it.second);
            if(mark[hieu] == true) {
                cout << 1 << '\n';
                return;
            } 
        }
        cout << 0 << '\n';
    }
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        freopen("bai3.inp", "r", stdin);
        freopen("bai3.out", "w", stdout);
        int t = 1;
        cin >> t;
        while(t--) {
           AC();     
        }
        return 0;
    }
    

  • 0
    leminh09  đã bình luận lúc 27, Tháng 4, 2025, 5:10

    alooo; sao của mình nó ghi Unexpected EOF in the participant's output chán quá


  • 0
    ______  đã bình luận lúc 6, Tháng 4, 2024, 8:39

    vài case kì quá, có cái 1 ra 0 cái khác thì đúng hết, k bt sao luôn =(


    • 1
      vudinhlong  đã bình luận lúc 6, Tháng 4, 2024, 14:12

      vector của bạn lưu pair(i, n/i) đi, duyệt for lồng, mỗi cặp tính tổng ra xong so với hiệu của các cặp còn lại