# **Contest Hè** **Link Submit:** [**HERE**](http://qboj.zapto.org/contest/cthe01) # 696969696969696969696969 #### **SOLUTION** :::spoiler C++ ```c++= #include <bits/stdc++.h> using namespace std; int n; int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cin >> n; if (n % 9 != 0) cout <<n % 9; for (int i = 0; i < n / 9; i++) cout <<9; return 0; } ``` ::: --- # Tổng Dãy Con #### **SOLUTION** :::spoiler C++ ```c++= #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, q; long long pre[maxn]; int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cin >>n >>q; for (int i = 1; i <= n; ++i){ int x; cin >>x; pre[i] = pre[i - 1] + x * (x > 0); } while (q--){ int l, r; cin >>l >>r; cout <<pre[r] - pre[l - 1] <<'\n'; } } ``` ::: --- # Một Bài Toán Của Đề HSG Chỗ Mô Đó #### **SOLUTION** :::spoiler C++ ```c++= #include <bits/stdc++.h> using namespace std; bool check(string s){ int sum = 0; bool k = 0; f0(i, n){ (sum += s[i] - '0') %= 3; if (s[i] == '0') k = 1; } return !sum && k; } string s; int n; int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cin >>n >>s; if (check(s)) sort(s.begin(), s.end(), greater<char>()), cout <<s; else cout <<-1; } ``` ::: --- # Số Lẻ VCL ( Vô Cùng Luôn ) #### **SOLUTION** :::spoiler C++ ```c++= #include <bits/stdc++.h> using namespace std; int n, res; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cin >>n; while (n--){ int x; cin >>x; res ^= x; } cout <<res; return 0; } ``` ::: --- # Bán Nguyên Tố #### **SOLUTION** :::spoiler C++ ```c++= #include <bits/stdc++.h> using namespace std; const int lim = 1e6; vector<bool> prime (lim + 1, 1); void sieve(){ prime[0] = prime[1] = 0; for(int i = 2; i <= lim / i; ++i) if (prime[i]) for (int j = i * i; j <= lim; j += i) prime[j] = 0; } bool ok(ll x){ ll sqx = sqrt(x); return prime[sqx] && sqx * sqx == x; } int n, res; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); sieve(); int q; cin >>q; while (q--){ ll x; cin >>x; cout <<ok(x) <<'\n'; } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up