0% found this document useful (0 votes)
30 views4 pages

Permanent CPP

The document includes header files and definitions for common C++ functions and data structures. It defines several macros for commonly used terms. It also includes functions for tasks like finding the greatest common divisor, checking if a number is a prime, computing the lowest common multiple, and solving linear Diophantine equations.

Uploaded by

Ayush rishu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Permanent CPP

The document includes header files and definitions for common C++ functions and data structures. It defines several macros for commonly used terms. It also includes functions for tasks like finding the greatest common divisor, checking if a number is a prime, computing the lowest common multiple, and solving linear Diophantine equations.

Uploaded by

Ayush rishu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

// दुरेण ह्यवरं कर्म बुद्धियोगाद्धञ्जय

//बुद्धौ शरणमन्विच्छ कृ पणाः फलहेतवः//

#include<iostream>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<climits>
#include<cmath>
#include<bitset>
#include<string>
#include<unordered_set>
#include<unordered_map>
#include<cstdlib>
#include<iomanip>
using namespace std;
#define f first
#define se second

#define int long long


#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii unordered_map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue< int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define ps(x,y) fixed<<setprecision(y)<<x
#define all(x) x.begin(),x.end()
#define endl "\n"
#define rep(i,st,en) for(ll i=st;i<en;i++)
#define inf 1e10

#define w(x) int x; cin>>x; while(x--)


int __gcd(int a , int b) {return b == 0 ? a : __gcd(b, a % b);}
int powmod(int a, int b) {int res = 1; if (a >= mod)a %= mod; for (; b; b >>=
1) {if (b & 1)res = res * a; if (res >= mod)res %= mod; a = a * a; if (a >= mod)a
%= mod;} return res;}

static bool cmp(pair<int, int>&a, pair<int, int>&b) {


return (a.second == b.second) ? a.first > b.first : a.second < b.second;
}

//int mini=*(min_element(all(arr)));

// int maxi=*(max_element(all(arr)));
void printArray (vector<int> arr)
{
for (int i = 0; i < arr.size(); i++) {
cout << arr[i] << " ";
}
cout << "\n";
}

bool prime[100005];
void SieveOfEratosthenes(int n)
{

memset(prime, true, sizeof(prime));

for (int p = 2; p * p <= n; p++)


{
// If prime[p] is not changed,
// then it is a prime
if (prime[p] == true)
{

for (int i = p * p; i <= n; i += p)


prime[i] = false;
}
}

}
int lcm (int a, int b)
{
return (a / __gcd(a, b)) * b;
}

int gcd(int a, int b, int& x, int& y) {


if (b == 0) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g) {
g = gcd(abs(a), abs(b), x0, y0);
if (c % g) {
return false;
}

x0 *= c / g;
y0 *= c / g;
if (a < 0) x0 = -x0;
if (b < 0) y0 = -y0;
return true;
}

bool checkperfectsquare(int n)
{

// square
if (ceil((double)sqrt(n)) == floor((double)sqrt(n))) {
return true;
}
else {
return false;
}
}

bool check(int a, int b, int c) {

int g = __gcd(a, b);


if (c % g) {cout << "NO" << "\n"; return false ;}
while (c % b && c > 0) c -= a;
if (c >= 0) return true;
else return false;

string test(string str, int n)


{
return str.erase(n, 1);
}
void solve() {

signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

freopen("hello.txt", "r", stdin);


freopen("hey.txt", "w", stdout);

int t;
cin >> t;
while (t--)
{
solve();
}

cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << "\n";

return 0;
}

You might also like