Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
# specify list capacity MaxN = 101002 prime_list = [0]*MaxN prime_list[0] = prime_list[1] = 1 # mark all composite number with 1 for i in range(2, MaxN): if prime_list[i] == 1: continue j = i*2 while j < MaxN: prime_list[j] = 1 j += i # then replace all '0' and '1' with prime number i = MaxN-2 while i > 0:...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
def generate_primes(n): # Create a boolean array "prime[0..n]" and initialize # all entries it as true. A value in prime[i] will # finally be false if i is Not a prime, else true. prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): # If prime[p] is not changed, then it is a p...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.Scanner; public class primeMatrix { public static int binarySearch(int valor, int[] datos) { int left=0, right=datos.length-1, avg; while (left<=right) { avg=(right+left)/2; if(datos[avg]==valor) { return avg; }else if(datos[avg]<valor && valor<datos[avg+1]) { avg++; ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class B { static StringTokenizer st; static Buffered...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import sys,math isprime = [0]*1000010 all_prime = [2] next_prime = [0]*1000010 def seive(): isprime[1] = isprime[0] = 1 limit = int(math.sqrt(1000010))+2 for i in range(4,1000010,2): isprime[i] = 1 for i in range(3,1000010,2): if(not isprime[i]): all_prime.append(i) ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
# Problem: B. Prime Matrix # Contest: Codeforces - Codeforces Round #166 (Div. 2) # URL: https://codeforces.com/problemset/problem/271/B # Memory Limit: 256 MB # Time Limit: 2000 ms # # Powered by CP Editor (https://cpeditor.org) from sys import stdin, stdout def INI(): return int(stdin.readline()) def INL(): r...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import math n, m = map(int, input().rstrip().split()) # dp = [[0] * m for _ in range(n)] row = [0] * n col = [0] * m # mat = [] def isPrime(x): if x in [2, 3, 5, 7, 11, 13, 17, 19]: return True if x == 1: return False for i in range(2,int( math.sqrt(x)) + 2): if x % i == 0: ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
numMax = 102001 numMin = 2 prime = [1] * numMax prime[1] = 0 prime[0] = 0 for i in range(numMin, numMax): j = i while(j+i < numMax): j += i prime[j] = 0 linha, coluna = map(int, raw_input().split()) matrix = [] for i in range(linha): values = list(map(int, raw_input().split())) matrix.append(values) saida ...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; string uppercase(string s) { transform(s.begin(), s.end(), s.begin(), ::toupper); return s; } string lowercase(string s) { transform(s.begin(), s.end(), s.begin(), ::tolower); return s; } set<pair<int, pair<string, int>>> sp; vector<vector<int>> v2d(5, vector<int>(5...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class CF_271_B_PRIME_MATRIX { static final int MAX = (int) (10e6+1); static boolean notPrime [] = new ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Apr 20 20:37:49 2020 @author: narayanaaramamurthy """ a,b=map(int,input().split()) c=100030 f=[0]*c f[1]=1 for i in range(2,c): if f[i]==0: for j in range(i+i,c,i): f[j]=1 t=0 for i in range(c-1,0,-1): if f[i]==0: ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import sys import collections import bisect prime = [-1] * 200000 i = 2 prime_list = [] while 200000 > i: if prime[i - 1] == -1: prime[i - 1] = 0 temp = i * 2 prime_list.append(i) while temp < 200000: prime[temp - 1] = 1 temp += i if i == 2: i += 1 else: i += 2 n, m = map(int, sys.stdin.readlin...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; vector<long long> prime; bool isprime[1000001]; void find_prime() { memset(isprime, true, sizeof isprime); for (long long i = 2; i <= sqrt(1000000); i++) { if (isprime[i] == true) { for (long long j = i * i; j <= 1000000; j += i) { isprime[j] = false; ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import math R = lambda: map(int, raw_input().split()) n, m = R() a = [R() for i in range(n)] M = 110000 p = [0, 0] + [1] * M for i in range(2, M): for j in xrange(2, int(math.sqrt(i) + 1)): if i % j == 0: p[i] = 0 break last = 10**10 for i in reversed(range(1, M)): if p[i]...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import math n,m = map(int,input().split()) grid = [list(map(int, input().split())) for _ in range(n)] def seive(): s = 10**5 + 10 primes = [True] * (s) primes[0] = False primes[1] = False for i in range(2,int(math.sqrt(s))+1): j = 2 while(j*i<s): #print(j*i) ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; const int LIMIT = 1000005; int sieve[LIMIT + 1]; int primes[LIMIT + 1]; int mark_primes() { int primeCount = 1; for (int i = 0; i <= LIMIT; ++i) sieve[i] = 0; for (int i = 2; i <= LIMIT; ++i) { if (!sieve[i]) { primes[primeCount] = i; sieve[i] = primeC...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
// package codeforces1; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import java.io.*; import java.math.*; import java.text.*; public class B166 { static InputReader in = new InputReader(System.in); static OutputWriter out = new OutputWriter(System.out); public stat...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.*; import java.util.*; public class second { static long fast_power(long a,long n,long m) { if(n==1) { return a%m; } if(n%2==1) { long power = fast_power(a,(n-1)/2,m)%m; return ((a%m) * ((power*power)%m))%m; } long power = fast_power(a,n/2,m)%m; return (power*power)%m; ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Task271B { public static void main(String... args) throws NumberFormatException, IOException { Solutio...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.math.BigInteger; import java.util.*; import java.text.*; public class cf271b { static BufferedReader br; static Scanner sc; static PrintWriter out; public static void ini...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.Scanner; public class Main2 { public static void main(String args[]){ Scanner input = new Scanner(System.in); int row = input.nextInt(); int col = input.nextInt(); int[][] matrix = new int[row][col]; for(int i = 0 ; i < row ; i++){ for(int j = 0 ;...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; im...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; vector<long long int> prime; bool arr[100009]; void sieve() { long long int k = sqrt(100009); for (int i = 3; i <= k; i += 2) { if (arr[i] == 0) { for (long long int j = i * i; j < 100009; j += 2 * i) { arr[j] = 1; } } } arr[1] = 1; for...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.*; public class primeMatrix { static boolean[] primes = new boolean[1000001]; public static void sieve() { Arrays.fill(primes, true); primes[0] = false; primes[1] = false; for (int i = 2; i < primes.length; i++) { if (!primes[i]){continue;} f...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
lm=100018;p=[1,1]+[0]*lm for i in range(2,lm):p[i*i::i]=[1]*(lm/i-i+1) for i in range(lm,0,-1):p[i]*=p[i+1]+1 I=lambda _:map(int,raw_input().split());n,m=I(0);M=map(I,[0]*n) print min(sum(p[i]for i in r)for r in M+zip(*M))
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
# aadiupadhyay import os.path from math import gcd, floor, ceil from collections import * import sys mod = 1000000007 INF = float('inf') def st(): return list(sys.stdin.readline().strip()) def li(): return list(map(int, sys.stdin.readline().split())) def mp(): return map(int, sys.stdin.readline().split()) def inp(): re...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
from sys import stdin,stdout input=stdin.readline import math,bisect num = 102001 numD = 2 prime=[1]*num prime[1]=0 prime[0]=0 for i in range(numD,num): j=i while(j+i<num): j+=i prime[j]=0 l=[] n,m=map(int,input().split()) for i in range(n): t=list(map(int,input().split())) l.append(t) ans=60000000 for i i...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int isprime[100005]; for (int i = 2; i < 100005; i++) isprime[i] = 1; isprime[1] = 0; for (int i = 2; i < 100005; i++) { if (isprime[i]) { v.push_back(i); for (int j = i + i; j < 100005; j += i) isprime[j] = 0; } }...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.*; public class CF271B { static boolean[] primes = new boolean[100004]; static TreeSet<Integer> tset = new TreeSet<>(); public static void main(String[] args) { sieve(); Scanner sc = new Scanner(System.in); int r=sc.nextInt(); int c =sc.nextInt(); ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
from bisect import bisect_left MAX_P = 100100 is_prime = [True] * MAX_P primes = [] is_prime[0] = is_prime[1] = False for i in xrange(2, MAX_P): if is_prime[i]: primes.append(i) for j in xrange(i + i, MAX_P, i): is_prime[j] = False n, m = map(int, raw_input().split()) a = [map(int, raw_...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> int main() { int x[501][501], i, j, ans, k, a[100101], b[32000], num[501][501], n, m, l; long long int ansx[501], ansy[501], minx, miny; for (i = 2; i <= 100100; i++) a[i] = 1; k = 0; for (i = 2; i <= 500; i++) { if (a[i] == 1) { for (j = i * i; j <= 100100; j += i) a[j] = 0...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
n,m=map(int,input().split()) s=[[*map(int,input().split())] for _ in " "*n] limit=int(1e5+2) l=[1,1]+[0]*limit for i in range(2,limit): l[i*i::i]=[1]*((limit-i*i)//i+1) for i in range(limit,-1,-1): l[i]*=l[i+1]+1 for i in range(n): for j in range(m): s[i][j]=l[s[i][j]] print(min(min(sum(i) for i ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int x = input.nextInt(); int y = input.nextInt(); int l; int g = 200000; int[][] z = new int[x][y]; int[] ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; const int mxn = 1000001; int prime[mxn]; void sieve() { for (long long int i = 0; i < mxn; i++) prime[i] = 0; prime[0] = prime[1] = 1; for (int i = 2; i * i < mxn; i++) { if (prime[i] == 0) { for (long long int j = i * i; j < mxn; j += i) prime[j] = 1; }...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
# -*- coding: utf-8 -*- # @Date : 2019-02-08 08:18:25 # @Author : raj lath (oorja.halt@gmail.com) # @Link : link # @Version : 1.0.0 from sys import stdin max_val=int(10e12) min_val=int(-10e12) def read_int() : return int(stdin.readline()) def read_ints() : return [int(x) for x in stdin.readline().spli...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; vector<bool> prime(2e5, true); void sieve() { for (int i = 2; i < prime.size(); i++) { if (prime[i] == true) { int k = 2 * i; while (k < prime.size()) { prime[k] = false; k += i; } } } } int main() { sieve(); int n, m; cin...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class Main1 { public static void main(String[] args) { Scanner in = new Scanner(System.in); //inputs int n = in.nextInt(); int m = in.nextInt(); ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
limite = int(10e5) primos = [True for i in range(limite)] primos[0] = False primos[1] = False for i in range(2,limite): if primos[i]: for j in range(i**2, limite, i): primos[j] = False distancias = [0 for i in range(limite)] distancias[0] = 2 distancias[1] = 1 base = int(limite//10 - 1) while n...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
def sieve(n): arr = [] prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 for p in range(2, n): if prime[p]: arr.append(p) return arr prime = s...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
######### ## ## ## #### ##### ## # ## # ## # # # # # # # # # # # # # # # # # # # # # # # ### # # # # # # # # # # # # # ##### # # # # ### # # # # # # # # ##### # # # # # # # # # # # # # # # # # # #########...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> primes; int sieveCountPrimesInRange(long long n) { vector<bool> isPrime(n + 1, true); int cnt = 0; isPrime[0] = isPrime[1] = 0; for (long long i = 1; i <= (n / i); i++) { if (isPrime[i]) for (long long j = i * 2; j <= n; j += i) isPrime[j] = 0;...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; const int MOD = 1e6 + 3; const int INFI = 1e9 * 2; const int N = 555; const int M = 111111; const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1}; bool p[M]; int next(int n) { int m = n; while (p[m]) m++; return m - n; } int r[N], c[N]; int mai...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265358979323; const double EPS = 1e-12; const int N = 1e6 + 5; const int mod = 1e9 + 7; vector<long long> v; void primearray() { bool prime[N]; memset(prime, 1, sizeof(prime)); prime[0] = 0; prime[1] = 1; for (int i = 2; i < sqrt(N); ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int pr[110000]; int prev = 0; pr[0] = pr[1] = 2; for (int i = 2; i < 110000; i++) { bool prr = true; for (int j = 2; j * j <= i; j++) if (i % j == 0) { prr = false; break; } if (prr) { for (int j = prev; j <...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
ncrivo = int(10e5) crivo = [True for i in range(ncrivo)] crivo[0] = False crivo[1] = False for i in range(2, ncrivo): if crivo[i]: for j in range(i ** 2, ncrivo, i): crivo[j] = False # frequencia contador = [0 for i in range(ncrivo)] contador[100000] = 3 for i in range(99999, -1, -1): if c...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
MX = 100500 prime = [True for i in xrange(MX+10)] ds = [0 for i in xrange (MX+10)] a = [[0 for i in xrange (510)] for j in xrange (510)] def sieve(): prime[0] = prime[1] = False for i in range (3,MX,2): if (prime[i] == True): for j in range (3*i,MX,2*i): prime[j] = False ...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; bool arr[1000000 + 100]; void findPrime(int size) { memset(arr, true, sizeof(arr)); arr[0] = false; arr[1] = false; for (int i = 2; i <= size; i++) if (arr[i]) for (int j = i + i; j <= size; j += i) arr[j] = false; } int main() { int n, m; while (cin >...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.Scanner; public class B { boolean primes[] = new boolean[100091]; public void generate(int n){ primes[0] = true; primes[1] = true; for(int i = 2 ; i <= (int)Math.sqrt(n) ; i++){ for(int j=i+1 ; j<=n ; j++){ if( !primes[j] && j%i==0 ) primes[j] = true; } } ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
def get_input_matrix(): user_input = input().split() n = int(user_input[0]) m = int(user_input[1]) matrix = [] for i in range(n): user_input_matrix = input().split() row = [] for j in range(m): row.append(int(user_input_matrix[j])) matrix.append(row) ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.*; import java.io.*; public class PA { /* Tyger! Tyger! burning bright In the forests of the night, What immortal hand or eye Could frame thy fearful symmetry? In what distant deeps or skies Burnt the fire of thine eyes? On what wings dare...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.math.BigInteger; import java.util.*; import java.text.*; public class cf271b { static BufferedReader br; static Scanner sc; static PrintWriter out; public static void ini...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
# Mateus Brito de Sousa Rangel - 117110914 limit = 300000 primes = [False for x in range(limit)] columns = [0 for x in range(limit)] ans = limit Input = map(int, input().split()) l, c = list(Input) def crivo(): primes[0] = True primes[1] = True for i in range(2, limit): if not primes[i]: ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import bisect MAX = 10**5+10 x =[True] * MAX for i in range(2, MAX): if x[i]: for j in range(i*2, MAX, i): x[j] = False ps = [i for i in range(2, MAX) if x[i]] I = lambda:map(int, raw_input().split()) n,m=I() r,c=[0]*n,[0]*m for i in range(n): a = I() for j in range(m): k = bisec...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#!/usr/bin/python3 n, m = tuple(map(int, input().split())) a = [list(map(int, input().split())) for _ in range(n)] simple = [0] * (10**5 + 4) simple[1] = 1 for i in range(2, 10**5 + 4): if simple[i] == 0: j = 2 while i * j < 10**5 + 4: simple[i * j] = 1 j += 1 simple[-1] = ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.*; public class cf271b { static boolean[] p = new boolean[1000001]; public static void sieve() { Arrays.fill(p, true); p[0] = false; p[1] = false; for (int i = 2; i <= 1000000; i++) { if (!p[i]) { continue; } ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.*; import java.math.*; import java.util.*; /** * * @author Togrul Gasimov (ttogrul30@gmail.com) * Created on 13.09.2013 */ public class Main { public static void main(String[] args) /*throws FileNotFoundException*/ { InputStream inputStream = System.in; OutputStream outputStream = Syste...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; public class P271B { public BitSet genPrimes(int n) { long [] lPrimes = new long [n / Long.SIZE + 1]; Arrays.fill(lPrimes, 0xAAAAAAAAAAAAAAAAL); BitSet primes = BitSet.valueOf(lPrimes); primes.flip(1, 3); primes...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
# Generate array of primes using Sieve of Eratosthenes def arrayOfPrimes(): n = 100000 prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 prime[0] = False prime[1] = False return prime # Generate...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
enter = input().split(" ") rows = int(enter[0]) columns = int(enter[1]) matrix = [] minMove = 100000 def is_prime(n: int): if n <= 3: return n > 1 if n % 2 == 0 or n % 3 == 0: return False i = 5 while i ** 2 <= n: if n % i == 0 or n % (i + 2) == 0: return False ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import math max_num = 110005 max_range = 505 n, m = map(int, raw_input().split()) d = [0 for i in xrange(max_num)] is_prime = [True for i in xrange(max_num)] is_prime[1] = False for i in xrange(2, 110001): if is_prime[i]: for j in xrange(i+i, 110001, i): is_prime[j] = False for i in xrange(11...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import math prm=[1 for i in range(101001)] prm[0]=0 prm[1]=0 for i in range(2,int(math.sqrt(101001))+1): if prm[i]==1: for j in range(i*i,101001,i): prm[j]=0 n,m=map(int,input().split()) arr=[] row=[0]*n col=[0]*m for i in range(n): l=list(map(int,input().split())) for k in range(m): ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
isPrime = [1] * 100010 def Prime(): global isPrime isPrime[0] = isPrime[1] = 0 for i in range(100010): if isPrime[i]: for j in range(2 * i, 100010, i): isPrime[j] = 0 Prime() n, m = map(int, input().split()) l = [] for i in range(n): l.append([int(x) for x in input()...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; set<int> primes; int sumr[500]; int sumc[500]; void addpr(int n) { bool b; int i, j; primes.insert(2); for (i = 3; i <= n; i += 2) { b = true; j = 3; while (b && j * j <= i) { b = i % j != 0; j += 2; } if (b) primes.insert(i); } } i...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class PrimeMatrix { public static void main(String[] args) { boolean[] isComp = new boolean[200002]; int[] v = new int[200002]; i...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.*; import java.util.*; public class B { int INF = Integer.MAX_VALUE / 1000; static Scanner sc = null; int MAX = 200001; public void solve() throws Exception{ int n = sc.nextInt(); int m = sc.nextInt(); int[][] d = new int[n][m]; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; int n, m; int matrix[500][500]; int min = -1; short primeMap[100500]; bool calcIsPrime(int n) { if (n < 2) return false; for (int i = 2; i <= sqrt(n * 1.); i++) { if (n % i == 0) return false; } return true; } void genPrimes() { primeMap[1] = -1; for (int i ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
n, m = map(int, raw_input().split()) g = [[] for i in xrange(n)] for i in xrange(n): g[i] = map(int, raw_input().split()) p = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,2...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
m, n = map(int, input().split(' ')) X = list(zip(*[map(int,input().split()) for i in [True] * m])) from bisect import bisect_left as bsl MaxPrime = 100004 def vec_primes(n): # See exercise 35. """ Returns a list of primes < n """ sieve = [True] * (n//2) for i in range(3,int(n**0.5)+1,2): if siev...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; vector<long long> v(1e5 + 1, -1); bool isprime(int t) { if (t == 2) return true; if (!(t % 2)) return false; for (int x = 3; x * x <= t; x += 2) { if (!(t % x)) return false; } return true; } int main() { int a, mn = INT_MAX, s; cin >> a >> s; v[1] = 1; ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#atal 2020.1, feito baseado nas noocoes vistas, conceito do crivuuuuus facilment eencontrado. import sys import math limit = 100025 minhaListadePrimos = [True for i in range(limit + 1)] primosSeguintestsss = [0 for i in range(200000)] def crivandu(): minhaListadePrimos[0] = minhaListadePrimos[1] = False fo...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
from sys import stdin, gettrace import bisect,sys if not gettrace(): def input(): return next(stdin)[:-1] # def input(): # return stdin.buffer.readline() def IP(): # to take tuple as input return map(int,stdin.readline().split()) def L(): # to take list as input return list(map(int,stdin.rea...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } vector<long long int> adj[100001]; long long int vist[10001]; void dfs(long long int node) { vist[node] = 1; for (long long int child : adj[node]) if (!vist[child]) dfs(child); } vector<long l...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 600; long long n, m, a, b, ans, arr[2][N]; vector<long long> prms; void build() { const int LIM = 1e6; bool num[LIM] = {}; for (long long i = 2; i < LIM; ++i) { if (num[i]) continue; prms.push_back(i); for (long long j = i * i; j < LIM; j += ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; struct cmpStruct { bool operator()(int const& lhs, int const& rhs) const { return lhs > rhs; } }; long long int power(long long int x, long long int y) { long long int res = 1; while (y) { if (y & 1) res = (res * x) % 1000000009; y = y / 2, x = (x * x) % 10000...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; const int inf = 0x7FFFFFFF; const double eps = 1e-9L; const double pi = acos(-1.0); using namespace std; int prime[100100 + 10], pf[100100 + 10]; int row[520], col[520], con[100100 + 5]; void make() { int count = 0; prime[count++] = 2; for (int i = 3; i < 100100; i +=...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.Scanner; public class PrimeMatrix { public static void main(String[] args) { Scanner in = new Scanner(System.in); boolean prime[] = new boolean[100004]; for (int i = 2; i < 50003; i++) { for (int j = 2; i * j < 100004; j++) { prime[(i * j) - 1] =...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOExcept...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
def generate_primes(n): primes, sieve = {}, [True] * int(n+1) for p in range(2, n + 1): if sieve[p]: primes[p] = p for i in range(p * p, n + 1, p): sieve[i] = False return primes def distance_prime(n, primes): if primes.get(n): return 0 ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
MOD = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) from bisect import * l = [1]*(10**5+100) for i in range(2,int((10**5+100)**0.5)+1): for j in range(i*i, ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; static const int N = 200000; void getSOE(vector<int>& p) { vector<bool> v(N + 1, true); v[0] = v[1] = false; for (int i = 2; i * i <= N; ++i) { if (!v[i]) continue; for (int j = i * i; j <= N; j += i) { v[j] = false; } ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class B { static BufferedReader in; static StringTokeniz...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
n,m=map(int,input().split()) limit=int(1e5+2) l=[1,1]+[0]*limit for i in range(2,limit): l[i*i::i]=[1]*((limit-i*i)//i+1) for i in range(limit,-1,-1): l[i]*=l[i+1]+1 s=[[l[j] for j in map(int,input().split())] for _ in ' '*n] print(min(min(sum(i) for i in s),min(sum(i) for i in zip(*s))))
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
row, col = [int(x) for x in raw_input().split()] matrix = [[int(x) for x in raw_input().split()] for _ in range(row)] MaxN = 100000+10 u=[1 for i in range(MaxN)] u[0] = u[1] = 0 for i in range(2,MaxN): if not u[i]: continue j = i while True: j += i if j >= MaxN: break ...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; vector<long long int> a(900005, 1); vector<long long int> v; void sieve(long long int nn) { for (long long int i = 2; i < nn; i++) { if (a[i]) { v.push_back(i); for (long long int j = 2; j * i < nn; j++) a[i * j] = 0; } } } signed main() { ios_base...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; const char nl = '\n'; const char gg = ' '; const int M = 1e5 + 5; bool mark[M]; vector<int> prime; void sieve() { int i, j, n; for (i = 3; i * i <= M; i += 2) { if (!mark[i]) { for (j = i * i; j < M; j += i + i) mark[j] = true; } } prime.push_back(2); ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.Scanner; public class PrimeMatrix { private static Scanner read = new Scanner(System.in); public static boolean isPrime(int a) { if (a < 2) return false; if (a != 2 && a % 2 == 0) return false; for (int i = 3; i * i <= a; i = i + 2) { if (a % i == 0) return false; } return ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
def crivo(limit): primes = [True] * limit primes[0] = False primes[1] = False for i in xrange(2, limit): if (primes[i]): for j in xrange(i * 2, limit, i): primes[j] = False return primes primes = crivo(10**5 + 100) n, m = map(int, raw_input().split()) matrix = ...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#!/usr/bin/env python primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101, 103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197, 199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311, 313,317,331,337,347,349,353,359,367,373,379,383,389,397,4...
PYTHON
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.*; import java.io.*; public class B{ static List<Integer> primes = new ArrayList(); static int[] p = new int[110001]; public static void sieve() { for(int i=2;i<=110000;i++) { if(p[i] == 0) { for(int j=2;i*j<=110000;j++) { p[i*j] = 1; } } } for(int i=2;i<=110000;i++)if(p[...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.*; import java.util.*; public class Sample { static int MAX = (int)(1e6+2); static int MOD=(int)1e9+7; static int countt = 0; public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub //BufferedReader br = n...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.*; import java.math.BigInteger; import java.util.*; /** * * @author Saju * */ public class Main { private static int dx[] = { -1, 0, 1, 0 }; private static int dy[] = { 0, -1, 0, 1 }; private static final long INF = (long) (1e15); private static final double EPSILON = 1e-10; private static ...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
a,b=map(int,input().split()) c=100030 f=[0]*c f[1]=1 for i in range(2,c): if f[i]==0: for j in range(i+i,c,i): f[j]=1 t=0 for i in range(c-1,0,-1): if f[i]==0: t=i f[i]=t l=[[int(j) for j in input().split()] for i in range(a)] for i in range(a): for j ...
PYTHON3
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; int main() { vector<int> prime(100009, 1); prime[0] = 0; prime[1] = 0; for (int i = 2; i * i <= 100009; ++i) { if (prime[i]) { for (int j = i * 2; j <= 100009; j += i) { prime[j] = 0; } } } int l = 0; for (int i = 100009; i >= 1; --...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.*; import java.io.*; public class L { static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st=new StringTokenizer(""); static public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> P; int t1; bool M[1000005]; int A[100005]; int rowsum[600], colsum[600]; int main() { P.push_back(2); for (int i = 3; i <= 1000; i += 2) for (int j = i * i; j <= 1e6; j += i) M[j] = 1; for (int i = 3; i <= 1e6; i += 2) { if (!M[i]) P.push_back(i); ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; long fact(long int w) { long int k, p = 0, l = 0, r = w; if (w == 1) return 1; else { while (p != 1) { for (k = 2; k <= pow(w, .5); k++) { if (w % k == 0) { l = 1; k = pow(w, .5); } } if (l == 0) p ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.io.*; import java.util.*; import java.lang.Math.*; public class Matrix1 { public static void main(String args[])throws Exception { boolean seive[]=new boolean[1000000]; Arrays.fill(seive,true); BufferedReader br=new BufferedReader(new InputStreamReader(System.i...
JAVA
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int a[100005]; set<int> b; for (int i = 2; i <= 100100; i++) { int flag = 0; for (int j = 2; j <= sqrt(i); j++) { if (i % j == 0) flag = 1; } if (flag == 0) b.insert(i); } set<int>::iterator it, it2; int r[505], c[505]; memse...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
#include <bits/stdc++.h> using namespace std; int a[100100], i, j, k; bool b[100100]; void seive() { a[0] = 2; a[1] = 2; a[2] = 2; for (i = 4; i <= 100100; i += 2) b[i] = 1; for (i = 3; i * i <= 100100; i += 2) { if (b[i] == 0) for (j = i * i; j <= 100100; j += i) b[j] = 1; } for (j = 100100; j ...
CPP
271_B. Prime Matrix
You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
2
8
import java.util.*; import java.io.*; public class pointonline{ static int n,k; static StringBuilder ans; static HashMap<Integer,Integer> map=new HashMap<>(); public static void main(String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ...
JAVA