Soluție HackerRank pentru Cutting Paper Squares, subdomeniul Fundamentals, în Java 8. Include cerința formatată, exemple, explicația pașilor și cod sursă.

  • Problemă: Cutting Paper Squares
  • Domeniu: Fundamentals
  • Limbaj: Java 8

Challenge: Cutting Paper Squares

Subdomeniu: Fundamentals (fundamentals)

Scor cont: 15.0 / 15

Submission status: Accepted

Submission score: 1.0

Submission ID: 464720061

Limbaj: java8

Link challenge: https://www.hackerrank.com/challenges/p1-paper-cutting/problem

Cerință

Mary has an n × m piece of paper that she wants to cut into 1 × 1 pieces according to the following rules:

- She can only cut *one piece of paper at a time*, meaning she *cannot* fold the paper or layer already-cut pieces on top of one another.
- Each cut is a straight line from one side of the paper to the other side of the paper. For example, the diagram below depicts the three possible ways to cut a 3 × 2 piece of paper:
![example-cutting-squares.png](https://s3.amazonaws.com/hr-challenge-images/26273/1476740077-bd1ab26d74-example-cutting-squares.png)

Given n and m, find and print the minimum number of cuts Mary must make to cut the paper into n · m squares that are 1 × 1 unit in size.

Input Format

A single line of two space-separated integers denoting the respective values of n and m.

Output Format

Print a long integer denoting the minimum number of cuts needed to cut the entire paper into 1 × 1 squares.

Constraints

- 1 ≤ n, m ≤ 10^9

Cod sursă

import java.util.*;
public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println((sc.nextLong())*(sc.nextLong())-1);
    }
}
HackerRank Fundamentals – Cutting Paper Squares