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

#Define

The document contains C++ code snippets that define functions for: 1) Finding the greatest common divisor (GCD) of two numbers using Euclid's algorithm. 2) Performing depth-first search (DFS) on a graph using recursion to count nodes. 3) Performing breadth-first search (BFS) on a graph using a queue.

Uploaded by

Raj Kakadiya
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)
58 views4 pages

#Define

The document contains C++ code snippets that define functions for: 1) Finding the greatest common divisor (GCD) of two numbers using Euclid's algorithm. 2) Performing depth-first search (DFS) on a graph using recursion to count nodes. 3) Performing breadth-first search (BFS) on a graph using a queue.

Uploaded by

Raj Kakadiya
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<bits/stdc++.

h>
using namespace std ;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define dd double
#define vv vector<ll>
#define mp make_pair
#define pp pair<ll,ll>
#define ff first
#define ss second
#define vp vector<pp>
#define pb push_back
ll const MOD=1e9+7;

int main()
{
fast;

ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result *


x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b
%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll ipow(int x, int p){


lint ret = 1, piv = x;
while(p){
if(p & 1) ret = ret * piv % mod;
piv = piv * piv % mod;
p >>= 1;
}
return ret;
}

ll fact(int x){
lint ret = 1;
for(int i=1; i<=x; i++) ret = ret * i % mod;
return ret;
}

ll bino(int x, int y){


return fact(x) * ipow(fact(x - y) * fact(y) % mod, mod - 2) % mod;
}

//#no. of prime divisors of number(i) Ex. 10-->(2,5)


vector<int> Prime(3002, 0);

for(int k = 2; k < 3001; k++){


if (Prime[k] == 0){

for(int a = 2*k; a < 3001; a += k){

Prime[a] += 1;
}
}
}

int count = 0;

for(int a = 1; a <= n; a++){


if(Prime[a] == 2){
count += 1;
}
}

cout << count << endl;

int gcd(int a, int b)


{
if (b == 0)
return a;
return gcd(b, a % b);

void isprime()
{
memset(prime,true,N);
for(ll i=2;i*i<N;i++)
{
if(prime[i]==true)
{
for(ll j=i*i;j<N;j+=i)
{
prime[j]=false;
}
}
}
}
ll power(ll a,ll n)
{
ll ans=1;
a=a%mod;
while(n>0)
{
if(n&1)
{
ans=(ans*a)%mod;
}
n=n>>1;
a=(a*a)%mod;
}
return ans;
}

///dfs

vector<int> val[100007];
bool visit[100007];
ll cnt=0;

void dfs(int ind)


{

visit[ind]=true;
for(int it=0;it<val[ind].size();it++)
{
ll xm=val[ind][it];
if(!visit[xm])
{

if(val[xm].size()-1>val[ind].size())
cnt++;

dfs(xm);
}
}

}
int main()
{
fast;

int n,m,i,u,v;
cin>>n>>m;

for(i=1;i<=m;i++)
{
cin>>u>>v;
val[u].pb(v);
val[v].pb(u);
}

for(i=1;i<=n;i++)
{
if(!visit[i])
{

dfs(i,val);

}
}
}

///bfs using queue

void bfs(int s){


vector<int> p(nodes+1,-1);
vector<bool> used(nodes+1,false);
queue<int> q;

q.push(s);
used[s]=true;
while(!q.empty()){
int v=q.front();
q.pop();

for(int e:adj[v]){
if(!used[e]){
q.push(e);
p[e]=v;
used[e]=true;

}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy