Skip to content

Instantly share code, notes, and snippets.

View Masud-Parves's full-sized avatar
🎯
Focusing

Pervej Mia Masud-Parves

🎯
Focusing
  • Software Engineer, Samsung R&D Institute Bangladesh
  • Shariatpur
View GitHub Profile
@Masud-Parves
Masud-Parves / Z_Algo.cpp
Last active January 14, 2020 15:52
Z Algorithm ( String Matching Algorithm)
void z_function(string s)
{
int n = (int) s.length();
vector < int > Z(n);
Z[0] = 0; // Z[0] = 0 ধরে নিলাম
for (int i = 1, L = 0, R = 0; i < n; ++i)
{
if (i <= R) // i সিগমেন্টের ভিতরে তা প্রথমেই চেক করে নিলাম
Z[i] = min (R - i + 1, Z[i - L]); // সিগমেন্টে z[i] = z[i-L] থেকে কম বা সমান হতে পারে *শর্ত চেক
else
@Masud-Parves
Masud-Parves / z_algorithm(Brute Force).cpp
Created January 4, 2020 19:06
z_algorithm( Brute Force/ Trivial algorithm )
void z_algo(string s){
int n = (int) s.length();
vector<int> z(n);
z[0] = 0; // z[0] = 0 or z[0] = n according to problem statement;
for(int i=1; i<n; ++i){
while (i + z[i] < n && s[z[i]] == s[i + z[i]]){
++z[i];
}
}
}
@Masud-Parves
Masud-Parves / C_RUN & CPP_RUN.txt
Last active March 14, 2019 20:31
Run C++ in Sublime Text 3
C_RUN:
{
"shell_cmd" : "gcc $file_name -o ${file_base_name}",
"working_dir" : "$file_path",
"variants":
[
{
"name": "Run",
@Masud-Parves
Masud-Parves / Kruskals_Algo.cpp
Created December 26, 2018 14:42
Minimum Spanning Tree - Kruskal’s Algorithm
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a) (int)a.size()
#define all(a) a.begin(), a.end()
@Masud-Parves
Masud-Parves / TotientSieve.cpp
Created December 5, 2018 16:53
Euler's Phi Function(Sieve).cpp
#define M 1000005
int phi[M]; // প্রতিটা ইনডেক্সে টশিয়ান্ট ভ্যালু রাখার জন্য array
void totientSieve() {
for (int i = 1; i < M; i++) {
phi[i] = i;
}
for (int p = 2; p < M; p++) {
if (phi[p] == p) { // এখানে p প্রাইম নাম্বার
for (int k = p; k < M; k += p) {
@Masud-Parves
Masud-Parves / Euler's Phi Function.cpp
Last active December 5, 2018 16:40
Euler's Phi Function
int Totient_Phi(int n) {
if(n==1) return 1; // n=1 হলে সবসময় phi 1 হবে ।
int res = n;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
}
res -= res / i;
}
@Masud-Parves
Masud-Parves / Euler's Phi Function(Brute Force).cpp
Created December 5, 2018 15:08
Euler's Phi Function(Brute Force)
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
if(a%b==0) return b;
else gcd(b,a%b);
}
int main(){
@Masud-Parves
Masud-Parves / Contest Templete.cppp
Created December 3, 2018 09:05
Competitive Programming Contest Templete
#include<bits/stdc++.h>
using namespace std;
/*
Bismillahir Rahmanir Rahim
Problem :
Problem Link :
Topics :
#include<bits/stdc++.h>
using namespace std;
/*
Bismillahir Rahmanir Rahim
Problem : UVa 11344 - The Huge One
Problem Link : UVa 11344 - The Huge One
Topics : Divisibility Rules
#include<bits/stdc++.h>
using namespace std;
/*
Bismillahir Rahmanir Rahim
Problem : UVa 11344 - The Huge One
Problem Link : UVa 11344 - The Huge One
Topics : Moduler Arithmetic