# Zoo creatures | Hackerearth problem solution

## Zoo creatures | Hackerearth problem solution:-

A string is called a good string if and only if two consecutive letters are not the same. For example,

$\mathtt{\text{abcab}}$ and  $\mathtt{\text{cda}}$ are good while $\mathtt{\text{abaa}}$ and $\mathtt{\text{accba}}$ are not.

You are given a string $s$. Among all the good substrings of $s$ ,print the size of the longest one.

Input format

A single line that contains a string $s$ ($1\le |s|\le 2\cdot {10}^{5}$).

Output format

Print an integer that denotes the size of the longest good substring of $s$.

Sample Input
ab

Sample Output
2

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The complete string is good so the answer is $2$.

$10$

## Zoo creatures | Hackerearth problem solutionCode:-

Solution 1 ( Java language):-

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
class ZooCreatures {
static InputReader inputReader=new InputReader(System.in);
static void solve()
{
long a=inputReader.nextLong();
long b=inputReader.nextLong();
long l=lcm(a,b);
long ans1=l/a;
long ans2=l/b;
out.println(ans1+" "+ans2);
}
static long gcd(long a,long b)
{
if (b==0)
{
return a;
}
return gcd(b,a%b);
}
static long lcm(long a,long b)
{
return (a*b)/gcd(a,b);
}
static PrintWriter out=new PrintWriter((System.out));
public static void main(String args[])throws IOException
{
new Thread(null,null,"BaZ",99999999)
{
public void run()
{
try
{
int t=inputReader.nextInt();
while (t-->0) {
solve();
}
out.close();
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}.start();
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = snext();
while (isSpaceChar(c))
c = snext();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = snext();
while (isSpaceChar(c))
c = snext();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public String readString() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}

Solution 2 ( C++ language):-

This solution is based on the c++ language and you can submit ib c++14 and c++17 also.
In this solution first three lines of the main function is only for the decreasing the time of execution of the program..
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

This is your choice that you want to use this or not but in some cases the code may take more time in execution and that time we need it .

#include <bits/stdc++.h>
#define ll long long
#define gcn _getchar_nolock
#define gcu getchar_unlocked
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define pib pair<int, bool>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) a * b / __gcd(a, b)
#define sn(a, un) (un - a + 1) * (a + un) / 2
#define nc2(n) n * (n - 1) / 2
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int x, y;
cin >> x >> y;
int g = gcd(x, y);
int ans1 = y / g;
int ans2 = x / g;
cout << ans1 << " " << ans2 << "\n";
}
return 0;
}