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
from sys import stdin,stdout input=stdin.readline import math,bisect num = 102001 prime=[1]*num prime[1]=0 prime[0]=0 for i in range(2,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 in range(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
from bisect import bisect_left as bisect def primes(n): correction = (n%6>1) n = {0:n,1:n-1,2:n+4,3:n+3,4:n+2,5:n+1}[n%6] sieve = [True] * (n/3) sieve[0] = False for i in xrange(int(n**0.5)/3+1): if sieve[i]: k=3*i+1|1 sieve[ ((k*k)/3) ::2*k]=[False]*((n/6-(k*k)/6-1)/...
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.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import java.util.TreeMap; public class B { static final int MAX = 100500; public static void main(String[] args) { doIt(); } static void doIt() { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out);...
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 sieve(mx): a = [0] * (mx + 1) a[0] = a[1] = 1 for (i, e) in enumerate(a): if e == 0: for n in range(i*i, mx + 1, i): a[n] = 1 return a p = sieve(10**5 + 100) for i in range(10**5 + 99, 0, -1): p[i] *= p[i+1] +1 n,m = map(int, input().split()) cols = [0]*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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main { /** * @param args */ public static void main(String[] args) { boolean[] P = new boolean[1000000]; Arrays.fi...
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.math.*; import java.util.*; import java.io.*; import static java.lang.System.*; public class Solution { public static void main(String[] args) throws IOException { Scanner in= new Scanner(System.in); int n,m; int cnt=0; int a[][] = new int[501][501]; int b[][] = new int[501][501]; int c[][] ...
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
x,y=map(int,raw_input().split()) Maxprimos = 100100 primos=[True]*Maxprimos primos[0]=False primos[1]=False marked={} for i in range(2,Maxprimos): if primos[i]:#Los vamos a marcar for j in range(i+i,Maxprimos,i): primos[j]=False matriz=[] for i in range(x): matriz.append(map(int,raw_input()....
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 = input().split(" ") line = int(n) column = int(m) limit = 100025 primes_list = [True for i in range(limit + 1)] next_prime_distance = [0 for i in range(200000)] def sieve_primes(): primes_list[0] = primes_list[1] = False for i in range(2, int(math.sqrt(limit))): if primes_list[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.io.*; import java.math.*; import java.util.*; public class Task { private static int[] primes; private static int findNext(int a) { if(primes[primes.length/2] > a) return findNext(a, 0, primes.length/2); else if(primes[primes.length/2] < a) return findNext(a, primes.length/2, primes.length-...
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.*; public class CF271B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] prime = new int[1000000]; int size = 0; prime[size++] = 2; for (int i = 3; i <= 200000; i+=2) if (isPrime(i)) prime[size++] = i; int n = sc.nextInt(), m = sc.nextInt(); 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
#CRIVO ncrivo = 1000000 crivo = [True for i in xrange(ncrivo)] crivo[0] = crivo[1] = False for i in xrange(2, ncrivo): if not crivo[i]: continue for j in range(i * i, ncrivo, i): crivo[j] = False #lendo dados n, m = map(int, raw_input().split()) data = [] for i in xrange(n): data.append...
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 a[600][600]; bool isprime(int x) { if (x == 1) return 0; if (x == 2) return 1; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return 0; } return 1; } int v[600], h[600]; bool pr[100007]; vector<int> prr; int main() { int n, m; cin >> n >> m; 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
def sieve(n): p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 a,m = map(int,input().split()) no=100100 prime = [True for i in range(no+1)] sieve(no) prime[0]=False prime[1]=False req=[0]*no for i in range(no...
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; long long k, p, h, b[555][555], a[555555]; long long mid, n, o, r, l; bool y, m[1000001]; void s(long long r) { for (long long i = 2; i * i <= r; i++) { if (m[i] == false) { for (long long j = i * 2; j <= r; j += i) { m[j] = true; } } } 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.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Stack; import java.util.StringTokenizer; public class Main { static ArrayList<Integer> prime; public static void sieve() { boolean[] isPrime = new bool...
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.*; import java.io.*; public class B { static int[] primes; public static void genPrime(){ ArrayList<Integer> p = new ArrayList<>(); for(int i=2;i<=100000;i++){ boolean t = true; for(int j=0;j<p.size();j++){ if(i%p.get(j)==0){ t = false; break; } } if(t) p.a...
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 N = 510; const int M = 100100; int prime[M + 10], a[N][N], b[N][N], n, m; int main() { prime[1] = 1; for (int i = 2; i <= M; ++i) if (prime[i] == 0) for (int j = i + i; j <= M; j += i) prime[j] = 1; cin >> n >> m; for (int i = 1; i <= n; ++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
def main(): limit = 110000 nums = [0]*limit for i in xrange(2,limit): if not nums[i]: for j in xrange(i+i,limit,i): nums[j]=1 delta = 0 for i in range(limit-1,0,-1): if not nums[i]: delta = 0 else: nums[i]=delta delta+=1 nums[1] = 1 A = [] B = [] C = [] nsums = [] msums = [] n,m = [in...
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; template <typename T> void _read(T& t); template <typename T> void _read(vector<T>& v); template <typename T1, typename T2> void _read(pair<T1, T2>& p); template <typename T> void _read(T& t) { cin >> t; } template <typename T> void _read(vector<T>& v) { for (unsigned _...
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.*; public class B implements Runnable { final int cnt = 200000; private void Solution() throws IOException { boolean[] prime = new boolean[2 * cnt + 1]; Arrays.fill(prime, true); prime[0] = prime[1] = false; for (int i = 2; i * i <= 2 * cnt; i++) if (prime[i]) for...
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
k=[0]*(200001) primes=[] for i in range(2,200001): if k[i]==0: primes.append(i) for j in range(i,200001,i):k[j]=1 def bin(x): lo,hi=0,len(primes) ans=0 while lo<=hi: mid = (hi+lo)//2 if primes[mid]==x:return 0 if primes[mid]<x:lo=mid+1 else:ans=mid;hi=mid-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
def to_prime(n): step = 0 i = n while not is_prime[i]: step += 1 i += 1 return step R = 10 ** 5 + 300 is_prime = [0] * (R + 1) is_prime[1] = 1 d = 2 while d * d <= R: if not is_prime[d]: for i in range(d ** 2, R + 1, d): is_prime[i] = 1 d += 1 for i in rang...
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 prime[200005]; void sieve() { prime[0] = prime[1] = 1; for (int i = 2; i < 200005; i += 1 + (1 & i)) { if (!prime[i]) { if (i <= 200005 / i) for (int j = i * i; j < 200005; j += i) { prime[j] = 1; } for (int j = i - 1; 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; bool primes[100005]; int sol[100005]; void sieve() { memset(primes, true, sizeof primes); primes[0] = primes[1] = false; int i, j; for (i = 2; i * i <= 100005; i++) { if (primes[i]) { for (j = i * i; j < 100005; j += i) primes[j] = false; } } int a...
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; bool compound[100030 + 1]; set<int> s; unsigned long long int l, h; int val, t; void criba() { for (int i = 2; i < 100030; i++) { if (!compound[i]) { s.insert(i); val = i + i; while (val <= 100030) { compound[val] = true; val += 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; vector<int> P; char crivo[1000000]; int m[512][512]; int mm[512][512]; int N, M; int main() { int i, n, a; memset(crivo, 0, sizeof(crivo)); for (i = 2; i < 1000000; i++) { if (crivo[i]) continue; P.push_back(i); for (n = i + i; n < 1000000; n += i) crivo[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; const int N = 1e6 + 5, M = 6e2; long long n, m, arr[M][M], cnt = 1e19, sum; vector<long long> v; bitset<N> isprime; void sieve() { isprime.set(); isprime[0] = isprime[1] = 0; for (int i = 2; i <= N / i; i++) { if (isprime[i]) { for (int j = i * i; j < N; 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
def I(): return(list(map(int,input().split()))) def sieve(n): p=2 primes=[True]*(n+1) primes[1]=False primes[0]=False while(p*p<=n): if primes[p]: # // Update all multiples of p greater than or # // equal to the square of it # // numbers which are multiple of p and are ...
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
n=100100 p=[0,0]+[1]*(n) p[0],p[1]=0,0 n1=int(n**0.5) for i in range(2,n1): if p[i]==1: for j in range(i*i,n,i): p[j]=0 for k in range(n,-1,-1): if p[k]: ind=k p[k]=0 else: p[k]=ind-k lst=[] x,y=map(int,input().split()) for j in range(x): l=[] for i in map(int,input().split()): l.ap...
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.io.*; import java.util.*; public class Round166Div2 { public static void main(String[] args) throws IOException { rd = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(System.out); st = new StringTokenizer(rd.readLine()); int N = Integer.parseInt(st.nextToken()), M = Inte...
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 Sieve(): p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0]= False prime[1]= False n = 10**5 + 12345 prime = [True for i in range(n + 1)] Sieve() n, m = [int(j) for j in input().split()...
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 gen_prime(n): num = [0 for i in range(n+1)] num[2] = 1 num[3] = 1 for i in range(4, n+1): isprime = True for j in range(2, int(i**0.5)+1): if num[j]: if not i%j: isprime = False break if isprime: num[i] = 1 prime = [] for i in range(2, n+1): if num[i]: prime.append(i) return ...
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
I = lambda :map(int , raw_input().split()) n , m = I() a = [I() for _ in xrange(n)] N = 110000 p = [0] * N _next = [0] * N for i in xrange(2 , N): if not p[i]: for j in range(i * i , N , i): p[j] = 1 cur_cnt = N - 1 for i in xrange(N - 1 , 1 , -1): if not p[i]: cur_cnt = i _next...
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 time primes = list() def generate_primes(): a=[0]*100010 for x in range(2,100004): if a[x]==0: primes.append(x) j=2 while j*x<100004: a[j*x]=1 j+=1 def bin_search(x): #if x < primes[0]: return -1 left = 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
MaxN=110010 u=[0 for i in range(MaxN)] u[0]=u[1]=1 for i in range(2,MaxN): if u[i]: continue j=i*2 while j<MaxN: u[j]=1 j+=i i=MaxN-2 while i>0: u[i]=u[i+1] if u[i] else i i-=1 n,m=map(int,raw_input().split()) a=[map(int,raw_input().split()) for i in range(n)] for i in range(...
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.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; //solution classes here public class Code { //main solution here static Scanner sc = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); static long mod = 998244353;//(l...
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
ncrivo = 1000000 crivo = [True for i in range(ncrivo)] crivo[0] = crivo[1] = False for i in range(2, ncrivo): if crivo[i]: for j in range(i * i, ncrivo, i): crivo[j] = False # lendo dados n, m = map(int, input().split()) data = [] for i in range(n): data.append(list(map(int, input().spl...
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; void fast_in_out() { std::ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); } int dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; int dy[] = {-1, 1, 0, 0, -1, -1, 1, 1, 0}; int lx[] = {2, 2, -1, 1, -2, -2, -1, 1}; int ly[] = {-1, 1, 2, 2, 1, -1, -2, -2}; const lo...
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> int a[501][501], p[100010]; int next(int n) { int i; for (i = n; p[i]; i++) ; return i; } int main() { int m, n, i, j, s, min = 10000000; p[0] = p[1] = 1; for (i = 2; i * i < 100010; i++) if (p[i] == 0) for (j = i * 2; j < 100010; j += i) p[j] = 1; scanf("%d%d", &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; long long count(int n) { if (n == 1) return 0; else if (n == 3) return 8; else return count(n - 2) + (n * 4 - 4) * floor(n / 2.0); } bool isPrime(int n) { int i, flag = 0; if (n % 2 == 0) flag = 1; else { for (i = 3; i <= sqrt(n); i += 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
#include <bits/stdc++.h> template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } using namespace std; const int N = 1e6; int p[N]; void solve() { long long int n, m, i, j, ans = INT_MAX; ...
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> bool v[110001]; int n, m, i, p[100001], c, j, Next[100001], k, w[501][501], S, Res = 999999999; int main() { p[c++] = 2; for (i = 3; i < 110000; i += 2) { if (v[i]) continue; p[c++] = i; for (j = 3 * i; j < 110000; j += i << 1) { v[j] = true; } } k = 0; for (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
def main(): entrada = input().split(" ") valor1 = int(entrada[0]) valor2 = int(entrada[1]) num1 = 100025 num2 = 2 matriz = [] primos = [True]*num1 primos = set_numeros_nao_primos(num1, num2, primos) for i in range(valor1): linha = list(map(int,input().split())) matri...
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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class BOOL { private static FastReader in =new FastReader(); static ArrayList<Integer> A=new ArrayList(); static HashMap <Integer,Integer> Map =new HashMap(); static boolean B[][]; sta...
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; bool isPrime(int x) { if (x < 2) return false; for (int i = 2; i <= sqrt(x); i++) if (!(x % i)) return false; return true; } int main() { int nextPrime[100000]; for (int i = 0; i < 100000; i++) { for (int j = i + 1;; j++) if (isPrime(j)) { ne...
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 def prime(n): ok= True for i in range(2, int(math.sqrt(n))): if(n%i==0): ok = False break if(ok): return True else: return False def fact(a,b): ans = 1 for i in range(a, b+1): ans*= i return str(ans)-1 def comb(n, c): 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
num1= 102001 num2= 2 prime=[1]*num1 prime[1]=0 prime[0]=0 for i in range(num2,num1): j=i while(j+i<num1): 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=100000 for i in range(n): tot=0 for j 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
import java.util.*; import java.io.*; public class palin { public static void main(String[] args) { Scanner scan = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); boolean prime[] = new boolean[100004]; for (int i = 2; i < 50003; i++) { for (int j = 2; i * j < 100004; j++) { prime...
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 N = 1000001; bool crib[N]; void criba() { memset(crib, true, sizeof(crib)); crib[1] = false; for (int i = 2; i <= N / 2; i++) { if (crib[i] == true) { for (int j = 2 * i; j <= N; j += i) { crib[j] = false; } } } } int mov_fila(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.LinkedList; import java.util.Scanner; public class Contest_5C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] input1 = sc.nextLine().split(" "); int rows = Integer.parseInt(input1[0]); int cols = Integer.parseInt(input1[1]); String[][] input2 = 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
# JOAO MARCELO - 2021 # 271B import math from bisect import bisect_left maxi = 100010 n, m = [int(x) for x in input().split()] tag = [0] * maxi lines = [0] * n cols = [0] * m prime = [0] * maxi tag[0] = tag[1] = 1 count = 0 for i in range(2, maxi): if(not tag[i]): prime[count] = i count += 1 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
import java.util.NavigableSet; import java.util.Scanner; import java.util.TreeSet; public class B271 { static NavigableSet<Integer> primes = new TreeSet<>(); static void initPrimes(int MAXN) { int sqrtN = (int)Math.sqrt(MAXN); boolean[] composite = new boolean[MAXN]; composite[0] = c...
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.*; public class B271 { public static boolean[] getListOfPrimalNumber() { int n = 100004; boolean[] arr = new boolean[n]; for (int p = 2; p < n; p++) arr[p] = true; for (int p = 2; p < n; p++) if (arr[p]) { for (int j = 2 * p; j < n; 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
m = 1000000 p=2 d = [-1]*(m) while p**2<=m: if d[p]==-1: for i in range(p*2, m , p): d[i]=0 p+=1 d[0]=0 d[1]=0 w=[] #print(d[:10]) g=0 for j in range(m-1,1,-1): if d[j]!= -1: w.append(g) else: g=j w.append(g) w.append(2) w.append(2) sq=w[::-1] #print(...
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 import sys def get_primes_distances(limit): distances = [0] * (limit +1) sieve = [True] * (limit + 1) sieve[0] = False sieve[1] = False i = 2 while (i * i <= limit): if (sieve[i] == True): for j in range(i * 2, (limit+1), i): sieve[j] = 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
def arr_inp(n): if n == 1: return [int(x) for x in stdin.readline().split()] elif n == 2: return [float(x) for x in stdin.readline().split()] else: return [str(x) for x in stdin.readline().split()] def count_prime(n): prim = defaultdict(lambda: 1, {i: 1 for i in range(n + 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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { private static final String Object = null; static BufferedReader in; static StringTokenizer st; static Pri...
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 N = 1000000; int prime[N], primes[N]; void sieve() { for (int i = 2; i <= N; i++) prime[i] = 1; for (int i = 2; i * i <= N; i++) if (prime[i]) for (int y = i * i; y <= N; y += i) prime[y] = 0; } int main() { sieve(); int idx = 0; for (int i = 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
def buil_prime_dict(n): a =[x for x in range(n+1)] a[1] = 0 lst = [] i = 2 while i <= n: if a[i] != 0: lst.append(a[i]) for j in range(i, n+1, i): a[j] = 0 i += 1 return lst prime_dict=buil_prime_dict(10**5+100) def diff_search_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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n, m; cin >> n >> m; long long mat[n][m]; for (long long i = 0; i < (long long)n; i++) { for (long long j = 0; j < (long long)m; j++) { cin >> mat[i][j]; } } vector<lon...
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 P271B { public static void main (String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int[][] matrix = new int[n][m]; boolean[] primes = Eratesten(100003); // int arrayMax = 1; // int index = 0; for (int i=0; i<n; 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> int n, m; int ers[101000]; int mp[101000]; int a[510][510]; int ans; int main() { int i, j, tmp; ers[0] = 1; ers[1] = 1; for (i = 2; i < 100100; i++) { if (ers[i] == 0) { for (j = i * 2; j < 100100; j += i) { ers[j] = 1; } } } j = 999999; for (i = 10010...
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.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.Enumeration; import java.util.Iterator; impo...
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 _min(x, y): if x < y: return x if y <= x: return y n = 100100 prime = [True for i in range(n+1)] prime[0], prime[1] = False, False p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 n = 100100 nextPrime = [0 for _ in range(n+1)] curren...
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 double EPS = 1e-6; const int PRECISION = 20; const int MOD = 1e9 + 7; struct node { long long val; vector<long long> formula; node() { val = -1; } }; struct group { long long mul, last, gcd; group(long long m, long long l, long long lm) { mul = m; la...
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
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
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; long long n, m, ans = 1e18; long long mat[505][505]; bool OK[100005]; vector<long long> primes; void Sieve() { for (long long i = 3; i < 100005; i += 2) OK[i] = 1; for (long long i = 3; i < 100005; i += 2) if (OK[i]) for (long long j = i * i; j < 100005; 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
n,m = map(int,raw_input().split()) arr = [] for i in range(n): arr.append(list(map(int,raw_input().split()))) primes = [] prime = [0 for x in range(100100)] prime[0] = prime[1] = 1 for i in range(2,100100): if not prime[i]: primes.append(i) for j in range(i+i,100100,i): prime[j] = 1 ...
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.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 t...
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 = 100005 primes = [True]*(n+1) primes[0] = False primes[1] = False p = 2 while(p*p<=n): if primes[p]: for i in range(p*p,n+1,p): primes[i] = False p += 1 plist = [] for i,val in enumerate(primes): if val: plist.append(i) def closestPrime(a): if primes[a]: return(a) first = 0 last = len(plist) - 1...
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 sys import math as mt import bisect as bi import collections as cc input = sys.stdin.readline I = lambda : list(map(int,input().split())) N = 10**5+100 prime = [] pr = [0]*(N) pr[0] = pr[1] = 1 for i in range(2,N): if not pr[i]: prime.append(i) for j in range(2*i,N,i): pr[j] = 1 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
//package com.example.programming; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import ...
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 a[505][505]; bool isprime[100005]; int prime[100005], x = 0; int bse(int temp) { int beg = 0, last = x - 1, an = 10000000000; while (beg <= last) { int mid = beg + (last - beg) / 2; if (prime[mid] == temp) return prime[mid]; else if (prime[mid] > t...
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 static java.lang.Math.*; import static java.util.Arrays.*; public class PrimeMatrix { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); //READ---------------------------------------------------- int n = sc.nextIn...
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.*; public class PrimeMatrix { static boolean[] isPrime; public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int min = Integer.MAX_VALUE; flagPrimes(999999); int[][] arr...
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.*; public class Main { // n levels and 4 vertex public static void main(String[] args){ Scanner sc= new Scanner(System.in); ArrayList<Integer> p= new ArrayList<>(); for (int i = 2; i <= 100000+10; i++) { boolean prime=true; for (int j= 2; j <= Math.sqrt(i); 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
import java.util.*; import java.io.*; import javafx.util.Pair; import java.math.BigInteger; import java.text.*; public class cf2 { static long mod = (long)1e9 + 7; static long mod1 = 998244353; static FastScanner f; static PrintWriter pw = new PrintWriter(System.out); static BufferedReader br; s...
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 dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {1, -1, 0, 0, 1, -1, -1, 1}; template <class T> void cmin(T& a, T b) { if (b < a) a = b; } template <class T> void cmax(T& a, T b) { if (b > a) a = b; } template <class T> int len(const T& c) { return (int)c.size(); } tem...
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
LIMIT = 100000+4 l, c = map(int, raw_input().split()) m = [ list(map(int, raw_input().split())) for x in xrange(l)] def is_prime(num): if num == 2 or num == 3: return True if num < 2 or num%2 == 0: return False if num < 9: return True if num%3 == 0: return False r = int(num**0.5) f = 5 while f <= r: ...
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.Scanner; public class PrimeMatrix { public static void main(String[] args) { System.out.println(); Scanner sc = new Scanner(System.in); boolean prime[] = SOE(1000000); int n = sc.nextInt(); int m = sc.nextInt(); int matrix[][] = new int[n][m]; int row[][] = new int[n][m]; int col...
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 PrimeMatrix { private static int MAX_INPUT = 100003; private static boolean[] generateAllPrimes() { boolean primeNumbers[] = new boolean[MAX_INPUT + 1]; for (int i = 0; i <= MAX_INPUT; i++) { primeNumbers[i] = true; } for (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
n, m = [int(s) for s in raw_input().split()] A = [None] * n for i in range(n): row = [int(s) for s in raw_input().split()] A[i] = row Amax = max([i for a in A for i in a]) def generate_primes(Amax): Amax = max(Amax, 10) numbers = [i for i in range(100004)] mapping = {n: True for n in numbers} mapping[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
import bisect import collections import copy import functools import heapq import itertools import math import random import re import sys import time import string from typing import List sys.setrecursionlimit(99999) p = [] mx = 10**5+1000 f = [0]*mx for i in range(2,mx): if f[i]==0: p.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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; public class practiceQuestions1 { static class Reader { final private int BUFFER_SIZE = 1 << 12; boolean consume = false; private byte[...
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 a[1000000], n, m, tmp, x, row[501], col[501]; vector<int> primes; void generate_primes() { for (long long i = 2; i < 1000000; ++i) { if (!a[i]) { primes.push_back(i); for (long long j = i * i; j < 1000000; j += i) { a[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
from sys import stdin,stdout,setrecursionlimit from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush,nlargest from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm , accumulate from bis...
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 os import sys import math import heapq from decimal import * from io import BytesIO, IOBase from collections import defaultdict, deque def r(): return int(input()) def rm(): return map(int,input().split()) def rl(): return list(map(int,input().split())) def prime(p): if p==1: 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
#include <bits/stdc++.h> using namespace std; long long n, m, kompos[1100010], a[1100][1100], b[1100][1100], temp; int main() { cin >> n >> m; kompos[1] = 1; for (long long i = 2; i * i <= 1100000; i++) { if (!kompos[i]) { long long j = i * i; while (j <= 1100000) { kompos[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
#include <bits/stdc++.h> using namespace std; bool notprime[100101]; void isprime() { int i, j; notprime[1] = true; for (i = 2; i <= 100100; i++) { if (notprime[i] == false) { for (j = i + i; j <= 100100; j += i) { notprime[j] = true; } } } } int cnt[501][501]; int main() { int 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
import java.io.*; import java.util.*; public class Main { static boolean[] isPrime; static ArrayList<Integer> primes; public static void sieve(){ isPrime = new boolean[1000_051]; primes = new ArrayList<>(); Arrays.fill(isPrime, true); isPrime[1] = isPrime[0] = false; for (...
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 oo = INT_MAX; int arr[1000000]; vector<int> p; void sieve() { arr[0] = arr[1] = 1; for (int i = 2; i < 1000000; ++i) { if (!arr[i]) { p.push_back(i); for (long long j = i; j * i < 1000000; ++j) { arr[i * j] = 1; } } } } int ...
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
maxn = 100100 ar = [1 for i in range(maxn)] ar[0], ar[1] = 0, 0 for i in range(2, maxn): if ar[i]: for j in range(i, (maxn - 1) // i + 1): ar[i * j] = 0 dst = maxn d = [dst for i in range(maxn)] for i in reversed(range(maxn)): if ar[i]: dst = 0 d[i] = min(d[i], dst) dst += 1 n, m = map(int, 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
import bisect def seive(): seive_arr = [True]*1000100 seive_arr[0] = False seive_arr[1] = False for i in range(2, 1000002): if(seive_arr[i]): for j in range(i*i, 1000002, i): seive_arr[j] = False primes = [] for i in range(1000002): if(seive_arr[i]): primes.append(i) return primes primes = seive(...
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.io.*; import java.math.*; import java.text.*; import java.util.*; public class Main { private static MyScanner in; private static PrintStream out; public static void main(String[] args) throws IOException { boolean LOCAL_TEST = false; out = System.out; if (LOCAL_TE...
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 static java.lang.System.*; import static java.lang.Math.*; import java.math.*; import java.util.*; import java.io.*; public class CodeForces { public static void main(String[] args) { boolean isPrime[]=new boolean[1000000]; isPrime[0]=true; for(int i=1; i<1000000; 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; vector<int> sv; bool mrk[300000]; int grid[700][700]; void filla() { for (int i = 2; i <= 200000; i++) { if (!mrk[i]) { sv.push_back(i); for (int j = 2; j * i <= 200000; j++) mrk[j * i] = 1; } } } int main() { filla(); int n, m; cin >> n >> m; ...
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.*; public class CN167B { static FastScanner in =new FastScanner(System.in); static boolean isComposite[] = new boolean[1000001]; static int INF = Integer.MAX_VALUE/2; public static void main (String args[]){ GharbalErnesten(1000000); isComposite[1]=true; isComposite[0]=tru...
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; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; long long t; vector<long long> v; long long arr[1000005]; void...
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 bisect n, m = map(int, raw_input().split()) matrix = [] for i in xrange(n): matrix.append(list(map(int, raw_input().split()))) primes = [i for i in xrange(101000)] primes[0] = -1 primes[1] = -1 only_primes = [] for i in xrange(len(primes)): if primes[i] != -1: only_primes.append(primes[i]) ...
PYTHON