# Cutting Paper Squares

# Cutting Paper Squares

JimNero009 + 4 comments Make sure you have enough memory to store the numbers ;)

mike_gorczynski + 0 comments Cheers mate. I was absolutely sure i figured it out so WHY IT WAS FAILING.

kinda silly, because it's a math problem, not core Java or Data structures problem.

fheil0815 + 0 comments kinda stupid. you would only need to add 1 line if the data types were correct.

sairajd044 + 0 comments Not a problem in Python

Bad_Jim + 0 comments Or, more accurately, make sure you are using a 64 bit or larger integer type.

TheCelestial_25 + 1 comment The reason beind mn - 1 can be understood like this. Forget about any grid for a moment, just imagine a simple piece of paper. Any cut on the paper will give rise to a new piece. If you make 1 cut to a single piece, it will give rise to 1 extra piece. If you further make a cut on any of those pieces, your count increases by one. In total, we need mn pieces, given each is 1x1. We don't have to make mn cuts, because there is already one piece at the beginning. So, we make mn - 1 cuts.

mukulodd1 + 1 comment Nice Explanation

TheCelestial_25 + 0 comments Thanks!

Bibliophage + 0 comments Each time a piece of paper is cut it becomes 2 pieces, adding 1 to the total number of pieces. Therefore to make x pieces from 1 piece there needs to be x-1 cuts, so the final answer is (n*m)-1.

Interestingly, this principle means that the cuts can be made in any order and configuration.

n_nenkov + 0 comments Those are not really math problems, but "take-care-of-large-integers" problems !!!

Oh, c'mon you guys !!!

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); } }

SquatchingMan + 1 comment I thought I was doing it right, but then needed to change the pre-written int's in main to long int's. c++ for those who run into the same issue.

SHIVUCODE + 0 comments yes... thanks

jessevsilverman + 1 comment For this problem to be ranked easy, it would be nice to see an example that wasn't one-dimensional solved all the way thru, to ensure we understand the rules for cutting. That is, sure, you can't fold or place them on top of eachother, but it is unclear whether you can hold multiple pieces of paper side by side as you cut. It seemed perfectly logical that one could, so I think an example where m, n both >1 would have cleared that question about the rules right up.

gidkessler + 1 comment ye i was thinking the exact same thing myself

jessevsilverman + 0 comments Actually, even Medium or Hard problems should just be harder or trickier to get working, not to understand what they are asking for. So what I said, but more so.

Admittedly, In Real Life, sometimes understanding what is actually needed, especially if it is non-identical to what was asked for, is a very important part of the problem. One big difference between here and LeetCode is that the problem descriptions tend to be more straightforward there, but more "fun" here. Glad they both exist.

tzych + 0 comments The answer is always one less than the number of 1x1 squares. Proof by induction: a single square takes zero cuts. If you have a rectangle of n squares that takes n-1 cuts, if you add a row or column of m squares, you are increasing the number of cuts by m as well, so the property is invariant.

shell87301 + 0 comments Really??

#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; cin >> n >> m; cout << m*n-1 << endl; return 0; }

atulmshr83 + 0 comments simple c++ code with data storing in as big datatype as long long int.

#include <bits/stdc++.h> using namespace std; unsigned long long int solve(unsigned long long int n, unsigned long long int m){ // Complete this function unsigned long long int row = n; unsigned long long int column = m; unsigned long long int count = (((row-1)*column)+(column-1)); return count; } int main() { unsigned long long int n; unsigned long long int m; cin >> n >> m; unsigned long long int result = solve(n, m); cout << result << endl; return 0; }

contractormeher1 + 0 comments import java.io.

*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*;public class Solution {

`// Complete the solve function below. static long solve(int n, int m) {`

if( n == 1 && m == 1){

`return 0;`

}else if(n == 1 && m > 1) {

`return m-1;`

}else if(n > 1 && m == 1){

`return n-1;`

}else {

`return (n*m)-1; } } private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) throws IOException { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); String[] nm = scanner.nextLine().split(" "); int n = Integer.parseInt(nm[0]); int m = Integer.parseInt(nm[1]); long result = solve(n, m); bufferedWriter.write(String.valueOf(result)); bufferedWriter.newLine(); bufferedWriter.close(); scanner.close(); }`

} what is wrong with the code??

Sort 51 Discussions, By:

Please Login in order to post a comment