This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C_RUN: | |
{ | |
"shell_cmd" : "gcc $file_name -o ${file_base_name}", | |
"working_dir" : "$file_path", | |
"variants": | |
[ | |
{ | |
"name": "Run", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
/* | |
Bismillahir Rahmanir Rahim | |
Problem : | |
Problem Link : | |
Topics : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
NewerOlder