luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/TIMUOC #778

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Tìm ước của 1 số - Luyện Code Online

https://luyencode.net/problem/TIMUOC

quanTDN commented 2 years ago

klu

kakanvk commented 1 year ago

Đề lạ quá Admin ơi, giới hạn của p là 1<p<n => n luôn lớn hơn 1, mà điều kiện của n thì là 1≤n≤10^18

Leducphat1234 commented 1 year ago

ước dương bất kì là sao vậy mọi người

btLong402 commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình. Mà mình cũm hông hỉu sao nó AC được =))

Xem code AC

```cpp #include using namespace std; #define ll long long ll n; map isPrime; void Prime() { for (ll i = 2; i <= 1000; i++) isPrime[i] = true; isPrime[0] = isPrime[1] = false; for (ll i = 2; i * i <= 1000; ++i) { if (isPrime[i]) for (ll j = i * i; j <= 1000; j += i) isPrime[j] = false; } } ll solve() { ll j = floor(sqrt(n)); for(ll i = 2; i <= 1000; i++){ if(isPrime[i]){ if(n % i == 0) return i; } } for (ll i = j; i <= n; i += 1) { if (n % i == 0) return i; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // clock_t start, end; // double duration; // start = clock(); Prime(); // end = clock(); // duration = ((double)(end - start)) / CLOCKS_PER_SEC; // cout << duration << "(s)\n"; int T; cin >> T; while (T--) { cin >> n; cout << solve() << endl; } return 0; } ```

phuong109 commented 1 year ago

Code của bạn btLong402 khi chạy với số n=2147483647 (quá nhỏ so với max của đề; nó là SNT max kiếu longint); code của bạn chạy trong 6,5s vậy mà vẫn acc? Tác giả ducla0104 thiên vị khi ra đề với ngưỡng như vậy (cho chạy 5 test, mỗi test 10^18; chạy trong 1s?). Không hay tí nào!

phuong109 commented 1 year ago

Thiệt là "ảo tung chảo" quá sức.

KituruMudw commented 1 year ago

không biết sao bị lỗi, các bạn xem thử giúp mình vs

try:
    Q = int(input())
    if not 1 <= Q <= 5:
        exit()
    for i in range(Q):
        n = int(input())
        if not 1 <= n <= 10**18:
            exit()
        for p in range(n-1, 1, -1):
            if n % p == 0:
                print(p)
                break
except:
    pass
102210292githug commented 1 year ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

```cpp #include using namespace std; #define MOD 1000000007 //#define base 31 #define rep(i, n) for(int i = 1; i <= (n); i++) #define fo(i, n) for(int i = 0; i < (n); i++) #define per(i, n) for(int i = (n); i >= 1; i--) #define rfo(i, n) for(int i = (n-1); i >= 0; i--) #define pb push_back #define ff first #define ss second #define vt vector #define all(x) x.begin(),x.end() #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) typedef unsigned long long ull; typedef long long ll; typedef pair pii; typedef pair pli; typedef pair pll; typedef map mii; typedef vt vti; const double Pi = acos(- 1.0); const int N = 1e6+6; const int inf = INT_MAX; templateostream& operator<<(std::ostream& os, const std::vector& vec) {for(T i : vec) os << i << ' '; return os;} void solve(){ ll n; cin >> n; if(n % ll(sqrt(n)) == 0){ cout << sqrt(n) << endl; return; } for(ll i = 2; i <= sqrt(sqrt(n)+1); i++){ if(n % i == 0) { cout << i << endl; return; } } for(ll i = floor(sqrt(n)); i >= sqrt(sqrt(n)+1); i--){ if(n % i == 0) { cout << i << endl; return; } } } int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int t = 1; cin >> t; while(t--) {solve(); } return 0; } /* Test: */ /* ```