1787A - Exponential Equation - CodeForces Solution


constructive algorithms math

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

#define     pb                push_back
#define     all(v)            v.begin(),v.end()
#define     vl                vector<int>
#define     in(a)             for(auto &x : a) cin>>x;
#define     out(a)            for(auto &x : a) cout<<x<<" "
#define     pr(a)             cout<<a<<endl
#define     N                 (int)(1e5 + 10) ///100010
#define     nl                "\n"
#define     mod               1000000007
#define     pr(x)             cout<<x<<"\n"
#define     sz(x)             ((int) x.size())
#define     test              int T; cin>>T; while(T--)
#define     yes               cout<<"Yes"<<endl;
#define     no               cout<<"No"<<endl;
#define     lcm(a,b)           (a*(b/__gcd(a,b)))


typedef long long ll;
typedef long double ld;
typedef long long int lli;
using namespace std;

vector<int> graph[N];
bool visited[N];
ll x;

//binary search using recursion
void bs(int l, int h, int arr[], int n)
{
    if(l<=h)
    {
        int m = (l+h)/2;
        if(n<m) bs(m+1, h, arr, n);
        else if(n>m) bs(l, m-1, arr, n);
        else x = m; ///return Answer
    }

}

//binary search using itterative
void bsi(int l, int h, int arr[], int n)
{
    while(l<=h)
    {
        int mid =(l+h)/2;

    }
}

//Basic DFS
void dfs(int vertex)
{
//    if(visited[vertex]) return;
    visited[vertex] = true;

    for(auto child : graph[vertex])
    {
        if(visited[child]) continue;
        dfs(child);
    }
}

//sieve of Eratohthenes

void prime_generator(int n)
{
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    vector<int> veca;

    for (int i=2; i*i<=n; i++)
    {
        if(prime[i]==true)
        {
            veca.push_back(i);
            for(int j=i*i; j<=n; j+=i) prime[j] = false;
        }
    }


    for (int i=0; i<veca.size(); i++) cout<<veca[i]<<endl;
}

void solve()
{
    ll n;
    cin>>n;
    if(n%2) pr(-1);
    else cout<<1<<" "<<(n/2)<<endl;
}

int main()
{
//    ios_base::sync_with_stdio(0);
//    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--) solve();


}












Comments

Submit
0 Comments
More Questions

435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers
120. Triangle
102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix