Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
long long n,p,x,y,z;
cin>>n>>p>>x>>y>>z;
long long de = n*2 + 1;
long long nu;
if(p==1)
{
if(x==z)
nu = x;
else
nu = de-z;
}
else if(p==3)
{
if(x==z)
nu = x;
else
nu = de-x;
}
else if(p==2)
{
if(x==z)
nu=0;
else
nu = de - (x+z);
}
else
{
if(x==z)
nu=0;
else
nu = de - (x+z);
}
long long gc = __gcd(nu, de);
nu/=gc;
de/=gc;
cout<<nu<<" "<<de<<endl;
}
return 0;
}
# cook your dish here
# cook your dish here
import math
t=int(input())
for i in range(t):
a = [int(x) for x in input().split()]
n=a[0]
op=a[1]
x=a[2]
y=a[3]
z=a[4]
n1=n*2+1
if(op==1):
if(x<y and y<z):
m=n1-(z)
elif(x>y and y>z):
m=n1-z
else:
m=x
elif(op==2):
m=n1-(z+x)
elif(op==3):
if(x>y and y>z):
m=n1-x
elif(x<y and y<z):
m=n1-x
else:
m=x
elif(op==4):
m=n1-(z+x)
gc=math.gcd(m,n1)
m2=int(m/gc)
n2=int(n1/gc)
print(m2,end=" ")
print(n2)
#include<stdio.h>
long int gcd(long int a,long int b)
{
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
int main()
{
long int test;
scanf("%ld",&test);
while(test--)
{
long int n,t,x,y,z;
scanf("%ld%ld%ld%ld%ld",&n,&t,&x,&y,&z);
long int b1,b2,b3;
if(t==1)
{
if(x!=z)
{ b1=(2*n+1)-z;
b2=(2*n)+1;
b3=gcd(b1,b2);
printf("%ld %ld\n",b1/b3,b2/b3);
}
else
{ b1=z ;
b2=2*n+1;
b3=gcd(b1,b2);
printf("%ld %ld\n",b1/b3,b2/b3);
}
}
else if(t==2||t==4)
{
b1=(2*n+1)-(2*y);
b2=(2*n)+1;
b3=gcd(b1,b2);
printf("%ld %ld\n",b1/b3,b2/b3);
}
else if(t==3)
{
if(x!=z)
{
b1=(2*n+1)-(x);
b2=(2*n)+1;
b3=gcd(b1,b2);
printf("%ld %ld\n",b1/b3,b2/b3);
}
else if(x==z)
{
b1=z;
b2=2*n+1;
b3=gcd(b1,b2);
printf("%ld %ld\n",b1/b3,b2/b3);
}
}
}
return 0;
}
import java.util.Scanner;
import java.util.*;
import java.io.*;
import java.lang.Math;
import java.time.Clock;
import java.lang.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
class bonk
{
public static void main(String[] args) throws Exception
{
BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in));
int t = Integer.valueOf(reader.readLine());
while (t-- > 0) {
long[] data = Arrays.stream(reader.readLine().trim().split(" "))
.mapToLong(i -> Long.valueOf(i)).toArray();
long n = data[0];
long type = data[1];
long x = data[2];
long y = data[3];
long z = data[4];
long alfa = 2 * n + 1;
long up = 0;
if (type == 1) {
if (x < y) {
if (y > z) {
up = x;
} else if (y < z) {
up = 2 * n + 1 - z;
}
} else if (x > y) {
if (y > z) {
up = 2 * n + 1 - z;
} else if (y < z) {
up = x;
}
}
} else if (type == 2) {
if (x < y) {
if (y > z) {
up = 0;
} else if (y < z) {
up = 2 * n + 1 - x - z;
}
} else if (x > y) {
if (y > z) {
up = 2 * n + 1 - x - z;
} else if (y < z) {
up = 0;
}
}
} else if (type == 3) {
if (x < y) {
if (y > z) {
up = x;
} else if (y < z) {
up = 2 * n + 1 - x;
}
} else if (x > y) {
if (y > z) {
up = 2 * n + 1 - x;
} else if (y < z) {
up = x;
}
}
} else if (type == 4) {
if (x < y) {
if (y > z) {
up = 0;
} else if (y < z) {
up = 2 * n + 1 - x - z;
}
} else if (x > y) {
if (y > z) {
up = 2 * n + 1 - x - z;
} else if (y < z) {
up = 0;
}
}
}
long gcd=getGcd(up, alfa);
System.out.println(up/gcd + " " + alfa/gcd);
}
}
public static long getGcd(long a, long b)
{
if(b == 0)
return a;
return getGcd(b, a%b);
}
}
# cook your dish here
import math
def case1(N,y):
f = (math.gcd(y-1, N + 1))
a=[(y-1)//f, (N + 1)//f]
print(*a)
def case2(N,y):
f = (math.gcd(N - y, N + 1))
a= [(N - y)//f, (N + 1)//f]
print(*a)
def case3(N,y):
f = (math.gcd(N + 1 - 2 * y, N + 1))
a = [(N + 1 - 2 * y) // f, (N + 1) // f]
print(*a)
def case4(N,y):
f = (math.gcd(N + 2 - y, N + 1))
a = [(N + 2 - y) // f, (N + 1) // f]
print(*a)
def case5(N,y):
f = (math.gcd(y + 1, N + 1))
a = [(y + 1) // f, (N + 1) // f]
print(*a)
for _ in range(int(input())):
n,t,x,y,z=[int(x) for x in input().split()]
N=2*n
if ((t==1)and(y-x==1)and(x==z))or((t==3)and(y-x==1)and(x==z)):
(case1(N,y))
if ((t==1)and(y-x==1)and(x!=z))or((t==3)and(x-y==1)and(x!=z)):
(case2(N,y))
if ((t==2)or(t==4)):
(case3(N,y))
if ((t==1)and(x-y==1)and(x!=z))or((t==3)and(y-x==1)and(x!=z)):
(case4(N,y))
if ((t==1)and(x-y==1)and(x==z))or((t==3)and(x-y==1)and(x==z)):
(case5(N,y))
from fractions import gcd
for _ in range(input()):
num,t,x,y,z = map(int,raw_input().split())
if x==z:
m=x
n=(2*num)+1
l = gcd(m,n)
print m/l,n/l
else:
if t==2 or t==4:
m = (2*num)-(2*y)+1
n = (2*num)+1
l = gcd(m,n)
print m/l,n/l
elif t==1:
m = (2*num)+1-z
n = (2*num)+1
l = gcd(m,n)
print m/l,n/l
elif t==3:
if x==0:
print 1,1
else:
m = (2*num)+1-x
n = (2*num)+1
l = gcd(m,n)
print m/l,n/l
using System;
using System.Linq;
public class Test
{
public static long gcd(long a, long b)
{
long c;
while (b != 0)
{
c = a % b;
a = b;
b = c;
}
return a;
}
public static void Main(string[] args)
{
var T = int.Parse(Console.ReadLine().Trim());
while (T-- > 0)
{
var ntxyz = Console.ReadLine().Trim().Split().Select(int.Parse).ToList();
var N = (long)ntxyz[0];
var t = ntxyz[1];
var x = (long)ntxyz[2];
var y = (long)ntxyz[3];
var z = (long)ntxyz[4];
long m = 0;
long n = 0;
if (t == 2 || t == 4)
{
// x and z are different otherwise zero angle
// so it is in y which is pi - 2 * [pi / (2*N + 1)] * y
m = 2 * N + 1 - 2 * y;
n = 2 * N + 1;
}
else if (t == 1 || t ==3)
{
if (x == z)
{
m = x;
n = 2 * N + 1;
}
else
{
if (t == 1)
{
m = x + 2 * N + 1 - 2 * y;
n = 2 * N + 1;
}
else
{
m = z + 2 * N + 1 - 2 * y;
n = 2 * N + 1;
}
}
}
long g = gcd(m, n);
Console.WriteLine($"{m / g} {n / g}");
}
}
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let matrix, n;
const calculate = () => {
};
const gcd = (a, b) => {
//if(!a || !b) throw 'wrong';
let t;
while (b != 0){
t = b;
b = a % b;
a = t;
}
return a;
}
let testCount = 0;
let state = 0;
let result = '';
let output = [];
const go = (arr) =>{
let n = arr[0];
let t = arr[1];
let x = arr[2];
let y= arr[3];
let z = arr[4];
let db = 2*n +1;
if(y ===0) {
result += "1 " + db + '\n';
return;
}
if(x === 0 && t === 3) {
result += "1 1" + '\n';
return;
}
let du;
if(t === 2 || t === 4){
du = db - 2*y;
}else if(t === 1){ //AAB
if(x === z){
if(y > x){
du = x;
}else{
du = x;
}
}else if(x > z){
du = db - z;
}else{
du = db - z;
}
}else if(t === 3){ //ABB
if(x === z){
if(y > x){
du = x;
}else{
du = x;
}
}else if(x > z){
du = db - x;
}else{
du = db - x;
}
}
let g = gcd(du, db);
du /= g;
db /= g;
result += du +' ' + db + '\n';
};
const l = (...a) => {
console.log(...a);
}
const lineToIntArray = line => line.split(' ').map(el => parseInt(el));
rl.on('line', (line) => {
if(state === 0){
testCount = parseInt(line);
state = 1;
}else if(state === 1){
go(lineToIntArray(line));
process.stdout.write(result);
result = '';
return;
if(--testCount === 0){
process.stdout.write(result);
process.exit();
}
}else{
}
});
package main
import (
"bufio"
"fmt"
"os"
)
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }
func gcd(x int64, y int64) int64{
if(x==0){
return y
}
return gcd(y%x, x)
}
func main(){
defer writer.Flush()
var T int
scanf("%d\n", &T)
for i:=0;i<T;i++{
var n, t, x, y, z int64
scanf("%d %d %d %d %d\n", &n, &t, &x, &y, &z)
//fmt.Scan(&n, &t, &x, &y, &z)
var b int64 = n+n+1
var a int64
if(t==1){
if(x>y && y>z){
a = b-z
}else if(x>y && y<z){
a = y+1
}else if(x<y && y>z){
a = y-1
}else if(x<y && y<z){
a = b-z
}
}else if(t==2){
a = b-x-z
}else if(t==3){
if(x>y && y>z){
a = b-x
}else if(x>y && y<z){
a = y+1
}else if(x<y && y>z){
a = y-1
}else if(x<y && y<z){
a = b-x
}
}else if(t==4){
a = b-x-z
}
var k int64 = gcd(a, b)
a /= k
b /= k
printf("%d %d\n", a, b)
//fmt.Println(a, " ", b)
}
}
In our experience, we suggest you solve this A Pizza Slice CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the A Pizza Slice CodeChef Solution.
“I hope this A Pizza Slice CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.
Keep Learning!