Atcoder Beginner Contest 284 D - Happy New Year 2023 Solution
Problem Link: https://atcoder.jp/contests/abc284/tasks/abc284_d
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #define N 9000009
- vector<ll> prime;
- ll i, j;
- bool vis[N];
- void sieve() {
- for (i = 3; i * i <= N; i += 2) {
- if (vis[i] == 0) {
- for (j = i * i; j <= N; j += 2 * i) {
- vis[j] = 1;
- }
- }
- }
- prime.push_back(2);
- for (i = 3; i <= N; i += 2) {
- if (vis[i] == 0) {
- prime.push_back(i);
- }
- }
- }
- int main() {
- ll t, n, i, mx, cnt, cn, cp;
- sieve();
- int sz = prime.size();
- cin >> t;
- while (t--) {
- cin >> n;
- ll a, b, p, q;
- for (i = 0; i <= sz; i++) {
- if (n % prime[i] == 0) {
- if (n % (prime[i] * prime[i]) == 0) {
- q = n / (prime[i] * prime[i]);
- p = prime[i];
- } else {
- q = prime[i];
- p = sqrt(n / q);
- }
- break;
- }
- }
- cout << p << " " << q << endl;
- }
- }
No comments