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 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, h, i, j, t, m, l, r, q;
long long p = 0, k, w, z, x, y, d, p1, h1;
string s = "", st = "", s1 = "", s2 = "";
q = 1;
for (l = 0; l < q; l++) {
std::cin >> n >> m;
int a[n][m];
for (i = 0; i < n; i++)
for (j = 0; j < m; 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 | from sys import stdin
def f(i, s):
if s[i] == 0: return 0
k = 0
while s[i] != 0:
if i == 111111: return k
i += 1
k += 1
return k
def r(A, s, mi):
for _ in range(n):
k = [f(int(i),s) for i in stdin.readline().split()]
sk = sum(k)
mi = min(mi, sk)
... | 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 ints():
return map(int,raw_input().split())
def soe(n):
prime = [1]*(n+1)
p = 2
while(p*p<=n):
if prime[p] == 1:
for i in range(p*2,n+1,p):
prime[i] = 0
p += 1
return prime
p = soe(100500)
p[0] = -1
p[1] = 0
n,m = ints()
l = []
for _ in range(n):
... | 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.*;
public class PrimeMatrix {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader inp = new InputReader(inputStream);
PrintWriter out = new PrintWriter(ou... | 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{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int MAX = 100010;
BitSet bset = new BitSet(MAX);
bset.set(2);
for (int j = 3; j < MAX; j+=2) bset.set(j);
int sqrt = (int) Math.sqrt(MAX); ... | 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_primes():
prime = [True] * 100100
prime[0] = False
prime[1] = False
prime[2] = True
n = 2
while n < len(prime):
i = n + n
while prime[n] and i < len(prime) :
prime[i] = False
i += n
n += 1
return prime
primes = get_primes()
n, m = map(int, input().split())
diffs = [[-... | 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[100001];
int binsearch(int key, int imin, int imax) {
if (imax < imin)
return prime[imin];
else {
int imid = (imin + imax) / 2;
if (prime[imid] > key)
return binsearch(key, imin, imid - 1);
else if (prime[imid] < key)
return binsear... | 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 B166{
public static void main(String args[]){
new B166().run();
}
public void run(){
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
int n = Integer.parseInt(line.split(" ")[0]);
int m = Integer.parseInt(line.split(" ")[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 | #include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 100;
int main() {
bool flag[MAX];
for (int i = 0; i < MAX; i++) flag[i] = true;
flag[0] = flag[1] = false;
for (int i = 2; i * i < MAX; i++)
if (flag[i])
for (int j = i; j * i < MAX; j++) flag[i * j] = false;
vector<int> p;
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 | import sys, math
def rs():
return sys.stdin.readline().strip()
def ri():
return int(sys.stdin.readline().strip())
def ras():
return list(sys.stdin.readline().strip())
def rai():
return map(int,sys.stdin.readline().strip().split())
def main():
M = 100099
n,m = rai()
arr = []
for i in xran... | 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;
const int N = 2e5;
int vis[N + 2], r[502], c[502];
void init() {
for (int i = 2; i * i <= N; ++i)
if (!vis[i]) {
for (int j = i * i; j <= N; j += i) vis[j] = -1;
}
vis[0] = vis[1] = -1;
for (int i = N; i; --i)
if (vis[i]) vis[i] = vis[i + 1] + 1;
}
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.*;
import java.io.*;
public class Main {
static int[] nextPrimeDP;
static boolean isPrime(int x) {
if(x == 1) return false;
if(x == 2) return true;
if(x % 2 == 0) return false;
int sqrtx = (int) Math.sqrt(x);
for(int i = 3; i <= sqrtx; i += 2) {
... | 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 | #http://codeforces.com/problemset/problem/271/B
#---- Crivo -----
size = 100010
primes = size * [True]
primes[0] = False
primes[1] = False
for i in xrange(2, size, 1):
if (primes[i]):
for j in xrange(i*2, size, i):
primes[j] = False
#------------------
#--- Pass to make a prime mat... | 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;
inline void inpint(int &n) {
n = 0;
register int ch = getchar_unlocked();
bool sign = 0;
while (ch < 48 || ch > 57) {
if (ch == '-') sign = 1;
ch = getchar_unlocked();
}
while (ch >= 48 && ch <= 57) {
n = (n << 3) + (n << 1) + ch - 48, ch = getchar_u... | 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 bisect import bisect_left
def read():
return [int(c) for c in input().split()]
def sieve(n=101000):
ans = [True] * (n + 1)
ans[0] = False
ans[1] = False
for i in range(2, n // 2 + 1):
if ans[i]:
mul = 2 * i
while mul < n + 1:
ans[mul] = 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
const size_t M = 100100;
bool prime[M];
prime[0] = false;
prime[1] = false;
fill(prime + 2, prime + M, true);
for (int i = 2; i * i < M; ++i) {
if (prime[i]) {
for (int j = i + i; j < M; j += i) {
prime[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 | n=10**5+4
arr=[True for i in range(n)]
arr[0],arr[1]=False,False
for i in range(2,n):
if arr[i]==True:
curr=i
while i*curr<n:
arr[i*curr]=False
curr+=1
for i in range(10**5+3,-1,-1):
if arr[i]==True:
curr=i
arr[i]=curr-i
n,m=[int(x) for x 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 | from bisect import bisect_left as bl
n,m=map(int,input().split())
pn,l=[],[]
q=10**5+4
k=[True for i in range(q+2)]
for p in range(2,int(q**.5)+2):
if(k[p]==True):
for i in range(p**2,q+2,p):k[i]=False
for p in range(2,q+1):
if k[p]:pn.append(p)
for i in range(n):
a,x=list(map(int,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 | from bisect import bisect_left
def genprimes(limit):
lim = limit // 6
sieve = [False, True, True] * lim
lim = lim * 3 - 1
for i, s in enumerate(sieve):
if s:
p, pp = i * 2 + 3, (i + 3) * i * 2 + 3
le = (lim - pp) // p + 1
if le > 0:
sieve[pp:... | 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 PrimeMatrix271B
{
// WARNING: For efficiency purposes, true means is it NOT prime, false means prime
private static boolean[] primesieve(int size)
{
// True will mean it is NOT prime
boolean[] returnme = new boolean[size]; // Default in Java to all false
... | 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 | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
... | 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.Arrays;
import java.util.Scanner;
public class Main {
private Scanner sc = new Scanner(System.in);
private static double EPS = 1e-9;
private static final int INF = Integer.MAX_VALUE;
public static void main(String[] args) {
new Main().run();
}
private void run() {
... | 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 not crivo[i]:
continue
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... | 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>
int main() {
int ar[1000002] = {0}, i, j, n;
ar[0] = 1;
ar[1] = 1;
for (i = 4; i < 1000002; i = i + 2) ar[i] = 1;
for (i = 3; i <= sqrt(1000002); i = i + 2) {
if (ar[i] == 0) {
for (j = i * i; j < 1000002; j = j + 2 * i) {
ar[j] = 1;
}
}
}
int a[502][50... | 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;
map<int, int> v;
vector<int> vt;
void prime() {
int n = 1000003;
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p) prime[i] = false;
}
}
int 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, i, j, k, l, s, d;
bool prime[1000000 + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= 1000000; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= 1000000; i += p) prime[i] = false;
}
}
prime[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.Scanner;
public class primeNumber {
public static void main(String args[]) {
boolean prime[] = new boolean[1000000+1];
for(int i=0;i<1000000;i++)
prime[i] = true;
for(int p = 2; p*p <=1000000; p++)
{
if(prime[p] == 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 | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main extends PrintWriter {
BufferedReader in;
StringTokenizer stok;
final Random rand = new Random(31);
final int inf = (int) 1e9;
final long linf = (long) 1e18;
void solve() throws IOException {
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 | public class Main {
public static void main(String[] args){
java.util.Scanner input = new java.util.Scanner(System.in);
boolean [] isComposite = new boolean[100005 - 2 >> 1];
for(int n = 0 ; n*n < isComposite.length ; n++)
if(!isComposite[n])
for(int count = 4*n*n+12*n+9 ; count < 100005 ; count += 4*n+6... | 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.DataInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;
public class Main{
public static void main(String[] args) throws Exception {
Parserdoubt s = new Parserdoubt(System.in);
ArrayList<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;
bool isPrime(int n) {
if (n == 1) {
return 0;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
int main() {
int r, c, temp;
scanf("%d %d", &r, &c);
vector<int> values(r + c, 0);
for (int i = 0; i < r; 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 | from math import ceil,sqrt
def prime():
l = [0]*100001
n = 100001
l[0] = 2
l[1] = 2
l[2] = 2
l[n-1] = 100003
for i in range(n-2,2,-1):
flag = True
for j in range(2,ceil(sqrt(i)+1)):
if i%j==0:
flag = False
break
if flag:
... | 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> prime;
vector<bool> seive(1e6, 1);
void build() {
for (int i = 2; i * i < seive.size(); i++) {
if (seive[i])
for (int j = i * i; j < seive.size(); j += i) seive[j] = 0;
}
for (int i = 2; i < seive.size(); i++)
if (seive[i]) prime.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 | def sieve(n):
prime = [False, False] + [True] * (n - 1)
i = 2
while i * i <= n:
if prime[i]:
for j in range(i * i, n + 1, i):
prime[j] = False
i += 1
return [i for i in range(n + 1) if prime[i]]
def binarySearch(v):
n = len(p)
left, right = -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 | maxn = 150035
primos = [0 for x in range(maxn)]
def crivo():
primos[1] = primos[0] = 1
for i in range(2, maxn):
if primos[i] == 0:
for j in range(i + i, maxn, i):
primos[j] = 1
for i in range(maxn-2, -1, -1):
if (primos[i] != 0):
primos[i] += primos[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.Scanner;
public class matrix {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int a[][] = new int[n][m];
int c[][] = new int[n][m];
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 | def f(n):
m = int(n ** 0.5) + 1
t = [1, 0] * (n // 2 + 1)
t[0], t[1], t[2] = 1, 1, 0
for i in range(3, m):
if t[i] == 0: t[i * i :: 2 * i] = [1] * ((n - i * i) // (2 * i) + 1)
for i in range(n - 1, -1, -1):
if t[i]: t[i] = t[i + 1] + 1
return t
q = f(100007)
n, m = map(int, inp... | 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
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):
if p[i]:
for j in range(i * i, M, i): p[j] = 0
last = 10**10
for i in reversed(range(1, M)):
if p[i]: last = i
p[i] = last - i
res = 10*... | 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 mas_cerca(int a[], int izq, int der, int x) {
int mid = (izq + der) / 2;
int act = a[mid] - x;
int i = 0;
if (act == 0) {
return act;
}
while (act < 0) {
mid = (mid + 1 + der) / 2;
act = a[mid] - x;
}
while (act > 2 * x) {
mid = (izq + mid - 1) / 2;
act =... | 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 | m = 10**5+5
cri = [0]*m
pri = []
for i in range(2, m):
if cri[i] == 0:
cri[i] = 1
pri.append(i)
for j in range(i, m, i):
cri[j] = 1
dp = [0] * m
for a in range(len(pri)-1):
pa, pb = pri[a], pri[a+1]
for i in range(pa+1, pb):
dp[i] = pb-i
dp[0] = 2
dp[1] = 1
# print(dp[:10])
n, m = map(int, 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 | from bisect import bisect_left
def read():
return [int(c) for c in input().split()]
def sieve(n=100003):
ans = [True] * (n + 1)
ans[0] = False
ans[1] = False
i = 2
while i * i <= n:
if ans[i]:
mul = 2 * i
while mul < n + 1:
ans[mul] = 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 java.util.BitSet;
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Sara
*/
public class B_PrimeMatrix_166_271 {
static BitSet... | 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 main() {
const int N = 100005;
bool no[N] = {1, 1};
int col[501], row[501], n, m, i, j, x;
int vis[100005];
memset(vis, 0, sizeof(vis));
for (i = 2; i * i < N; ++i)
for (j = i * i; j < N; j += i) no[j] = 1;
for (int i = 0; i <= 100000; i++) {
int k = 0;
while (no[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 long n, m, arr1[509][509], rows[509], cols[509], z;
const int N = 1e6;
bool f[N + 5];
void seive() {
f[0] = f[1] = 1;
for (int i = 1; i <= N; i++) {
if (f[i]) continue;
for (long long j = (long long)i * i; j <= N; j += i) f[j] = 1;
}
}
int main() {
seiv... | 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 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.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
static final int nd=(int)1e5+10;
public static void main(String[] args) throws IOException {
FastReader in = 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 | import bisect
MAX = 10**5+10
x =[True] * MAX
for i in xrange(2, MAX):
if x[i]:
for j in xrange(i*2, MAX, i):
x[j] = False
ps = [i for i in xrange(2, MAX) if x[i]]
I = lambda:map(int, raw_input().split())
n,m=I()
r,c=[0]*n,[0]*m
for i in xrange(n):
a = I()
for j in xrange(m):
k = ... | 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 v[1000][1000];
set<int> st;
char erat[200000 + 100];
int main() {
int n, m, t;
cin >> n >> m;
for (int i = 0; i < 200000; ++i) erat[i] = true;
for (int i = 2; i < 110000; ++i) {
if (erat[i]) {
for (int j = i + i; j < 150000; j += i) erat[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.*;
import java.util.*;
public class primeMatrix {
public static void main(String[] args) {
InputStream input = System.in;
OutputStream output = System.out;
InputReader in = new InputReader(input);
PrintWriter out = new PrintWriter(output);
Solution s = new Sol... | 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.*;
import static java.lang.Math.*;
public class Solution {
BufferedReader in;
StringTokenizer st;
PrintWriter out;
TreeSet<Integer> sieve() {
boolean[] prime = new boolean[500000];
prime[0] = prime[1] = true;
for (int i = 2; i < prime.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 bisect
MAX = 10**5 + 10
sushu = [True] * MAX
for i in range(2, MAX):
if sushu[i]:
for j in range(i * 2, MAX, i):
sushu[j] = False
sushu = [i for i in range(2, MAX) if sushu[i]]
read = lambda : map(int, raw_input().split())
n, m = read()
r, c = [0] * n, [0] * m
for i in range(n):
a = read()
for j 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 | #include <bits/stdc++.h>
using namespace std;
vector<int> prime;
void runEratosthenesSieve(int upperBound) {
int upperBoundSquareRoot = (int)sqrt((double)upperBound);
bool *isComposite = new bool[upperBound + 1];
memset(isComposite, 0, sizeof(bool) * (upperBound + 1));
for (int m = 2; m <= upperBoundSquareRoot;... | 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
# Precalculo de primos
n = 10**6
prime = [True] * (n + 1)
prime[0] = False
prime[1] = False
m = int(math.sqrt(n))
for i in range(2, m+1, 1):
if (prime[i]):
for k in range(i+i, n+1, i):
prime[k] = False
# Problema
n, m = map(int, raw_input().split())
mA = []
linhas = []
colunas = []
... | 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 sieve(num):
primes = [0] * (num + 1)
prime_flag = [True] * (num + 1)
#referencia a 0 e 1.
prime_flag[0]=prime_flag[1] = False
i = 2
while(i*i <= num):
if(prime_flag[i]):
for j in range(i*i, num + 1, i):
prime_flag[j] = False
i += 1
for i in range(num-1, -1,-1):
if not pr... | 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;
template <class T>
inline T euclide(T a, T b, T& x, T& y) {
if (a < 0) {
T d = euclide(-a, b, x, y);
x = -x;
return d;
}
if (b < 0) {
T d = euclide(a, -b, x, y);
y = -y;
return d;
}
if (b == 0) {
x = 1;
y = 0;
return a;
} else... | 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
p = [2]
for i in range(3,100004):
pr = True
for pp in p:
if pp**2 > i:
break
if i % pp == 0:
pr = False
break
if pr:
p.append(i)
n, m = [int(i) for i in raw_input().split()]
mx = []
for i in range(n):
mx.append([int(i) for i in 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 com.sun.corba.se.impl.resolver.SplitLocalResolverImpl;
import sun.util.resources.cldr.zh.CalendarData_zh_Hans_HK;
import javax.swing.text.MutableAttributeSet;
import java.awt.event.MouseAdapter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflec... | 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 | //271B - Prime Matrix
public class Main {
public static void main(String[] args){
java.util.Scanner input = new java.util.Scanner(System.in);
//maximum element is 10^5
//array of the odd numbers <= 10^5 +3"three moves from 10^5 to next prime 10^5 +3"
boolean [] isComposite = new boolean[100004 - 2 >> 1];
fo... | 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.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;... | 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())
arr = [list(map(int, input().split())) for _ in range(n)]
N = int(1e5+4)
is_prime = [0] * N
is_prime[0] = is_prime[1] = 1
for i in range(2, N):
if is_prime[i] == 1: continue
for j in range(i*2, N, i):
is_prime[j] = 1
is_prime[-1] = N - 1
for i in range(N-2, 0, -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.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 | //package Demo;
import java.util.*;
public class Test {
public static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
int limit=100100;
///PRIME SIEVE
boolean[] arr=new boolean[limit+1];
//false=prime;true=not prime
arr[0]=true;arr[1]=true;;
for(int i=2;i*i<=limit;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.util.*;import java.io.*;import java.math.*;
public class Main
{
public static void process()throws IOException
{
boolean[] sieve=new boolean[200001];
Arrays.fill(sieve,false);
TreeSet<Integer>set=new TreeSet<Integer>();
for(int i=2;i<sieve.length;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.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;
public class zizo {
public static void main(String[] args) {
Scanner zizo = new Scanner(System.in);
int n = zizo.nextInt();
int m = zizo.nextInt();
sieve(1000000);
int min = Integer.MAX_VALUE;
int[][]grid = new int[n][m];
fo... | 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 const maxn = 100010;
vector<long long> pir(100011, 1);
vector<long long> pr;
void Sieve() {
pir[1] = pir[0] = 0;
for (int i = 2; i <= maxn; i++) {
if (pir[i]) {
pr.push_back(i);
for (int j = i * 2; j <= maxn; j += i) {
pir[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;
int main() {
int t, i, j;
bool isprime[100005];
memset(isprime, true, sizeof(isprime));
for (i = 2; i * i <= 100003; i++) {
if (isprime[i] == true) {
for (j = i * i; j < 100005; j += i) {
isprime[j] = 0;
}
}
}
int nprime[100005];
fo... | 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 STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
import sys
from heapq import heappop , heappush
from bisect import *
from... | 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;
priority_queue<int, vector<int>, greater<int> > Q;
const int INF = 1e9 + 9;
long int pow(long int a, long int b, int m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
vector<int> ans(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 bisect import bisect_left
def sieve(r):
D = dict()
yield 2
for q in range(3,r,2):
p = D.pop(q, None)
if not p:
D[q*q] = q
yield q
else:
x = p + q
while x in D or not (x&1):
x += p
D[x] = p
primes = lis... | 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 N = 505;
int in[N][N], row[N], col[N];
vector<int> primes;
void sieve() {
bitset<102005> status;
for (int i = 2; i < 102005; i++)
if (!status[i]) {
primes.emplace_back(i);
for (int j = i + i; j < 102005; j += i) status[j] = true;
}
}
int ma... | 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.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 | import sys
from collections import defaultdict, Counter
from itertools import permutations, combinations
from math import sin, cos, asin, acos, tan, atan, pi
sys.setrecursionlimit(10 ** 6)
def pyes_no(condition, yes = "YES", no = "NO", none = "-1") :
if condition == None:
print (none)
elif condition :
pri... | 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;
const int M1 = 100030;
const int M2 = 316;
bool pri[M1];
void se() {
int i, j, k;
pri[1] = 1;
for (k = 1, i = 2; i <= M2; i += k, k = 2)
if (!pri[i]) {
for (j = i * i; j < M1; j += i) pri[j] = 1;
}
}
int pr(int n) {
int i, j = 0;
for (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 | num1 = 100025
num2 = 2
primos = [True]*num1
for i in range(num2,num1):
j = i
while(j + i < num1):
j += i
primos[j] = False
primos[1] = False
primos[0] = False
matriz = []
n, m = map(int,input().split())
for i in range(n):
t = list(map(int,input().split()))
matriz.append(t)
resposta =... | 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 B {
static int MAX=1000000;
static boolean prime[]=new boolean[MAX+1];
static ArrayList<Integer> p = new ArrayList<Integer>();
static void sieve(){
for(int i=2;i*i<=MAX;i++){
if(!prime[i]) {
p.add(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 math
n, m = map(int, input().split())
matriz =[[*map(int,input().split())] for _ in " "*n]
primos, prox_primo = [], [0] * 100100
def eh_primo(x, primos):
for i in primos:
if i * i > x:
break
if x % i == 0:
return False
return True
for i in range(2, 100100):
if eh_primo(i, primos):... | 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[] primes = new boolean[100004];
static TreeSet<Integer> tset = new TreeSet<>();
static List<Integer> l = new ArrayList<>();
public static void main(String[] args) {
sieve();
Scanner sc = new Scanner(System.in);
... | 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 math
from collections import defaultdict
import sys
primeCache = defaultdict(list)
def primeSieve(n):
primes = []
primeCache[1].append(1)
primeCache[2].append(2)
primes.append(2)
for i in range(2, n):
if i not in primeCache:
primes.append(i)
primeCache[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 | def main():
from sys import stdin
base_lcm = 30
content = stdin.readlines()
n, m = map(int, content[0].split())
matrix = [list(map(int,line.split())) for line in content[1:]]
result_matrix = [0]*m
minn = 43000
mn = min
for row in xrange(n):
row_sum = 0
for col in x... | 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
MAX_SIZE = 100001
isprime = [True] * MAX_SIZE
prime = []
SPF = [None] * (MAX_SIZE)
d = dict()
def manipulated_seive(N):
isprime[0] = isprime[1] = False
for i in range(2, N):
if isprime[i] == True:
prime.append(i)
d.setdefault(i,1)
SPF[i] = i
j = 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;
int n;
vector<int> prime;
void creating_seive(bool a[], int n) {
for (int i = 2; i <= (int)(pow(n, 0.5)); i++) {
if (a[i] == 1) {
int k = 0;
for (int j = i * i; j <= n; j = i * i + k * i) {
a[j] = 0;
k++;
}
}
}
for (int 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 | #Sieve
max_value = 1000000
prime = [True for i in range(max_value + 1)]
prime[0] = prime[1] = False
p = 2
while (p * p <= max_value):
if(prime[p]):
for i in range(p*2, max_value + 1, p):
prime[i] = False
p += 1
#Question
row, col = map(int, input().split())
matrix = []
for i in range(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 | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int>> matrix(n, vector<int>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> matrix[i][j];
}
}
vector<int> sieve(200001, 0);
vector<int> primes;
for (int i = 2; i < 20... | 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 | limite = 100000
crivo = [True]*(limite + 1)
crivo[0] = False
crivo[1] = False
i = 2
while(i*i <= limite):
if (crivo[i] == True):
for j in range(i * 2, (limite+1), i):
crivo[j] = False
i += 1
crivo[100000] = 100003
for i in range(99999, -1, -1):
if(not crivo[i]):
if(type(crivo[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 | def is_prime(x, primes):
for i in primes:
if i * i > x:
break
if x % i == 0:
return False
return True
n, m = [int(x) for x in input().split()]
a = []
primes = []
for i in range(2, 110000):
if is_prime(i, primes):
primes.append(i)
next = [0] * 110000
next[0] = 2
for x in primes:
val = x
while next[x] ... | 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/contest/271/problem/B
# Memory Limit: 256 MB
# Time Limit: 2000 ms
# Powered by CP Editor (https://github.com/cpeditor/cpeditor)
import math
from sys import stdin
def get_ints(): return list(map(int, stdin.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 java.util.Scanner;
import java.util.Arrays;
public class Main271B
{
static boolean[] prime=new boolean[1000001];
static int[] diff=new int[100001];
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
preprocess();
int n=sc.nextInt();
int m=sc.nextInt();
in... | 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 |
// @author Sanzhar
import java.io.*;
import java.util.*;
import java.awt.Point;
public class Template {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine()... | 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> arr(78498);
vector<vector<int>> in(505, vector<int>(505));
vector<vector<int>> out(505, vector<int>(505));
void SieveOfEratosthenes(int n) {
vector<bool> prime(n + 1, true);
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = 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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
public class ProblemB {
static final ... | 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 | maxim= 100005
prime = [True] * maxim
prime[0] = False
prime[1] = False
for i in range(2,maxim):
if prime[i]:
for j in range(i+i, maxim,i):
prime[j] = False
n,m = map(int, input().split())
rows = [0]*n
cols = [0]*m
for i in range(n):
arr = list(map(int, input().split()))
for j in range(m):
x = arr[j]
whil... | 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.*;
/**
*
* @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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Solution {
// public static final double eps = 1e-9;
// public 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 | n, m = map(int, input().split())
maximum = 10 ** 5 + 3
prime = [True] * (maximum + 1)
prime[0], prime[1] = False, False
for i in range(2, maximum + 1):
if (prime[i]):
for j in range(i + i, maximum + 1, i):
prime[j] = False
matrix = []
sums = [[0] * n, [0] * m]
ans = 1e9 + 7
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 | #include <bits/stdc++.h>
using namespace std;
void sieve(vector<int> &a, int n) {
vector<bool> siever(n + 10, 1);
int m = (int)sqrt(n);
for (int i = 2; i < m; i++) {
if (siever[i] == 0) continue;
for (int j = i * i; j <= n; j = j + i) {
if (siever[j] != 0) siever[j] = 0;
}
}
int coun = 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 | /*input
3 3
1 2 3
5 6 1
4 4 1
*/
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static PrintWriter out;
static int MOD = 1000000007;
static FastReader scan;
/*-------- I/O using short named function ---------*/
public static String ns(){return scan.next();}
public static 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 | from bisect import bisect_left as bl
n,m=map(int,input().split())
pn,l=[],[]
q=10**5+4
k=[True for i in range(q+2)]
for p in range(2,int(q**.5)+2):
if(k[p]==True):
for i in range(p**2,q+2,p):k[i]=False
for p in range(2,q+1):
if k[p]:pn.append(p)
for i in range(n):
l.append(list(map(int,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 | import sys
input = lambda: sys.stdin.readline().strip("\r\n")
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
n, m = map(int, input().split())
no = 10 ** 5 + 100
prime = [True for i in range(... | 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;
bool numbers[100010];
void initi() {
for (int i = 0; i < 100010; i++) numbers[i] = true;
}
void seive() {
for (int i = 2; i * i <= 100010; i++) {
if (numbers[i] == true) {
for (int j = i * 2; j <= 100010; j = j + i) numbers[j] = false;
}
}
}
int main() {... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.