The Prime Cells
Tag(s):

## Basic Programming, Easy, Implementation

Problem
Editorial
Analytics

You are given a grid of size $n \times n$ filled with numbers in each of its cells. Now you need to count total cells in the grid such that the sum of the numbers on its top , left , right and bottom cells is a prime number. In case there is no cell in a particular direction assume the number to be as 0.
Input
First line contains a number n as input denoting size of the grid. Next n lines contain n numbers each denoting value of the elements of the grid in each row.
Output
In the output you have to give the count of total cells as described above.
Constraints
$2 \le n \le 100$
$1 \le g[i][j] \le 100$ where $g[i][j]$ is the value in the grid at $i^{th}$ row and $j^{th}$ column.

SAMPLE INPUT
2
1 2
3 4

SAMPLE OUTPUT
4
Explanation

In the given grid if we pick the first element that is 1 then to its right and bottom are 2 and 3 whose sum is 5 and so its prime. Note that to the left there is no element so we consider it as 0 and same goes for the up direction. Checking this for all yields that all the four cells contribute to the count of cells whose sum of the adjacent cell values is prime.

Time Limit: 2,0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in

Challenge Name

July Circuits '17

OTHER PROBLEMS OF THIS CHALLENGE
• Algorithms > Sorting
• Algorithms > Searching
• Algorithms > Graphs
• Algorithms > Dynamic Programming
• Algorithms > Graphs
• Data Structures > Trees
Уведомления

?