prompt
string
response
string
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const long long MAXN = 500 + 10; long long a[MAXN][MAXN], c[MAXN][MAXN]; bool isPrime[100 * 1000 + 100]; long long b[100 * 1000]; void findPrimes(long long n) { for (long long i = 0; i < n; i++) isPrime[i] = true; isPrime[0] = false; isPrime[1] = false; for (long lo...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#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++) ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import bisect from math import sqrt maxn = int(1e5 + 50) isprime = [1 for i in range(maxn+1)] d = [1E9 for i in range(maxn+1)] def sieve(): cross_limit = int(sqrt(maxn)) isprime[0] = isprime[1]= 0 for i in range(4, maxn+1, 2): isprime[i] = 0 for i in range(3, cross_limit+1, 2): if i...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int sieve[100005]; vector<int> arr; int mat[505][505]; long long int bbinary_search(int l, int r, long long int k) { if (r - l == 1) { if (arr[l] >= k) return l; else return r; } if (r == l) return r; int mid = (l + r) / 2; if (arr[mid] > k) ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class Main1 { public static void main(String[] args) { Scanner in = new Scanner(System.in); //inputs int n = in.nextInt(); int m = in.nextInt(); ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
limite = int(10e5) primos = [True for i in range(limite)] primos[0] = False primos[1] = False for i in range(2,limite): if primos[i]: for j in range(i**2, limite, i): primos[j] = False distancias = [0 for i in range(limite)] distancias[0] = 2 distancias[1] = 1 distancias[100000] = 3 for i in ra...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int n, x = 1e9, y = 1e9, z, a[1000][1000], k, sol, sum, MOD = 10000007, b[1000005], m; vector<int> v; pair<int, int> p[1000000]; map<int, int> ma; string s1, s2, s; void getprime() { b[1] = 1; for (int i = 2; i <= 1000000; i++) { if (b[i]) continue; for (...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int n, m; int a[512][512]; int b[512][512]; int table[512][512]; int sum1[512]; int sum2[512]; int NextPrime[131072]; const int inf = 1 << 30; int AnswerProblem = inf; bool IsPrime(int number) { if (number < 2) { return false; } int sq = sqrt(number), j; for (j ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import sys, math MaxN = 100500 np = [0 for i in range (MaxN)] for i in range (2, MaxN): j = 2 while j * j <= i: if i % j == 0: np[i] = 1 break j += 1 for j in range (MaxN - 2, 0, -1): if np[j] == 0: continue np[j] = np[j+1] + 1 np[1] = 1 n, m = (int (x) for x in sys.stdin...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int prime[200000]; int table[505][505]; memset(prime, 0, sizeof prime); prime[1] = prime[0] = -1; for (int i = 2; i < 200000; i++) if (prime[i] == 0) for (int j = 2 * i; j < 200000; j += i) prime[j] = -1; scanf("%d %d", &n, &m)...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.*; import java.util.*; public class Sample { static int MAX = (int)(1e6+2); static int MOD=(int)1e9+7; static int countt = 0; public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub //BufferedReader br = n...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import sys import math limit = 100025 list_primes = [True for i in range(limit + 1)] next_primes = [0 for i in range(200000)] def SieveOfEratosthenes(): list_primes[0] = list_primes[1] = False for i in range(2, int(math.sqrt(limit))): if list_primes[i]: j = 2 while i * j <= lim...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import sys import string import math import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache from fractions import Fraction def mi(s): return map(int, s.strip().split()) def lmi(s): return list(mi(s)) def tmi(s): retur...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.util.*; public class Forsa271B { private static boolean[] resheto; public static void main(String[] args) { resheto = fillResheto(100004); Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int[] rows = new int[n]; int[]...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int INF = ~(1 << 31); int M[507][507]; int D[507][507]; bool is_prime(int n) { if (n < 2) return false; if (n < 4) return true; if (n % 2 == 0 || n % 3 == 0) return false; if (n < 25) return true; for (int i = 5; i * i <= n; i += 6) if (n % i == 0 || n %...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
# aadiupadhyay import os.path from math import gcd, floor, ceil from collections import * import sys mod = 1000000007 INF = float('inf') def st(): return list(sys.stdin.readline().strip()) def li(): return list(map(int, sys.stdin.readline().split())) def mp(): return map(int, sys.stdin.readline().split()) def inp(): re...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.util.*; import java.io.*; public class uu { public static void main(String[] args) throws IOException, InterruptedException { Scanner sc =new Scanner(System.in); PrintWriter pw =new PrintWriter(System.out); int r=sc.nextInt(),c=sc.nextI...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
n,m=map(int,input().split()) limit=int(1e5+2) l=[1,1]+[0]*limit for i in range(2,limit): if not l[i]: l[i*i::i]=[1]*((limit-i*i)//i+1) for i in range(limit,-1,-1): l[i]*=l[i+1]+1 s=[[l[j] for j in map(int,input().split())] for _ in ' '*n] print(min(min(sum(i) for i in s),min(sum(i) for i in zip(*s))))
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.io.BufferedOutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.List; ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int p[100005]; vector<int> v; void sieve() { v.push_back(2); for (int i = 3; i < 100005; i += 2) if (!p[i]) { v.push_back(i); for (int j = 2 * i; j < 100005; j += i) p[j] = 1; } p[1] = p[2] = 2; int k = 1; for (int i = 3; i < 100005; i++) { ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e5 + 100 + 19, N = 500 + 19; int pp[Maxn], A[N][N], sum[N][N]; int n, m, x, Ans = (1 << 30) - 1; int main() { scanf("%d%d", &n, &m); for (int i = 2; i < Maxn; i++) if (!pp[i]) for (long long j = 1LL * i * i; j < Maxn; j += i) pp[j] = 1; pp[...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.util.Scanner; public class PrimeMatrix { public static void main(String[] args) { Scanner in = new Scanner(System.in); boolean prime[] = new boolean[100004]; for (int i = 2; i < 50003; i++) { for (int j = 2; i * j < 100004; j++) { prime[(i * j) - 1] =...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int n, m, a[505][505], cost[505][505], idx, ans = 1e9, sum, k; bool u[1000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); u[1] = 1; for (int i = 2; i <= 100000; i++) { if (!u[i]) { for (int j = i * 2; j <= 200000; j +=...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.Locale; import java.io.OutputStream; import java.util.RandomAccess; import java.io.PrintWriter; import java.util.AbstractList; import java.io.Writer; import java.util.List; import java.io.IOException; import java.util.Arrays; import java...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.awt.Point; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class Start { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; PrintWriter out; StringTokenizer t...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int n, m; int arr[509][502], s[100000]; int l = 1; int dem[1005], ans; int main() { s[0] = 2; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> arr[i][j]; } } for (int i = 3; i <= 100003; i++) { int k = 0; for ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
lm=100018 p=[1,1]+[0]*lm for i in range(2,lm): p[i*i::i]=[1]*(lm/i-i+1) for i in range(lm,0,-1): p[i]*=p[i+1]+1 I=lambda _:map(int,raw_input().split()) n,m=I(0) M=map(I,[0]*n) print min(sum(p[i]for i in r)for r in M+zip(*M))
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.*; import java.util.*; public class PrimeMatrix { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#! /Library/Frameworks/Python.framework/Versions/2.6/bin/python inp = raw_input().split() n = int(inp[0]) m = int(inp[1]) matrix = [[] for i in range(n)] for i in range(n): inp = raw_input().split() for j in range(m): matrix[i] += [int(inp[j])] def primesUpTo(n): primes = [] marked = [False]*(n+1) ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.PrintWriter; import java.util.*; public class B { public static void main(String[] args) { boolean[] primes = genPrimes(); PrintWriter out = new PrintWriter(System.out); Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int[][] matrix = new int[N][M]; int[]...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import sys; class MyReader: # file = null; def __init__(self): filename = "file.in"; if self.isLocal(): self.file = open(filename); self.str = [""]; self.ind = 1; def isLocal(self): return len(sys.argv) > 1 and sys.argv[1] == "SCHULLZ"; d...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.*; import java.util.*; public class PrimeMatrix { private static MyScanner in; private static PrintStream out; public static void main(String[] args) throws IOException { out = System.out; boolean usingFileForIO = false; if (usingFileForIO) { in ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.util.*; public class Main{ public static int [] PrimeTable = new int[ 100000]; public static int Count = 0; public static boolean isprime(int a){ if (a%2 == 0)return true; for (int i=3;i<=Math.sqrt(a) ; i+=2){ if(a % i == 0 ) r...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
N=110000 p=list(True for i in range(N)) Next=list(N for i in range(N)) def calc() : p[0]=p[1]=False for i in range(2,N) : if p[i] == True : j=i*i while j<N : p[j]=False j+=i last=N for i in range(N-1,0,-1) : if p[i] == True : last=i Next[i]=last calc() n,m=map(int,input().split()) a=list(list...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; import java.util.Arrays; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Igors */ public class CF166B { public static...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
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 xr = xrange for row in xr(n): row_sum = 0 ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from functools import lru_cache sys.setrecursionlimit(100000000) int_r = lambda: int(sys.stdin.readline()) str_r ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, t = 100010, sum = 0, mins = 100000; cin >> n >> m; set<int> s; vector<vector<int> > v(n, vector<int>(m)); vector<int> b(t + 1, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> v[i][j]; } } for (int i...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
number = 102001 numberD = 2 prime=[1]*number prime[1]=0 prime[0]=0 for i in range(numberD,number): j=i while(j+i<number): 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): tot=0 for...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; vector<int> v; int index(int x) { int mid; int low = 0; int high = v.size() - 1; while (low <= high) { mid = (low + high) / 2; if (v[mid] >= x) high = mid - 1; else low = mid + 1; } return high; } int a[505][505]; int a1[505][505]; int ro...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
def buil_prime_dict(n): lst=[0,0]+[1]*n for i in range(2,n): if lst[i]: for j in range(i*i,n,i): lst[j]=0 for k in range(n,-1,-1): if lst[k]: ind=k lst[k]=0 else: lst[k]=ind-k return lst prime_dict=buil_prime...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int MAXN = 550; int cnst = 1000 * 100 + 10; int r[MAXN], c[MAXN]; bool isPrime[1000 * 100 + 20]; vector<int> prime; void findPrimes(int n) { for (int i = 0; i < n; i++) isPrime[i] = true; isPrime[0] = false, isPrime[1] = false; for (int i = 2; i < n; i++) { ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int prime[100001] = {0}; bool check_prime(int n) { if (n == 1) { return 0; } if (n == 2) { return 1; } if (n == 3) { return 1; } for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return 0; } } return 1; } int next_prime(int n...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T a) { return a * a; } vector<int> pr; bool was[1 << 20] = {0}; void calc() { const int n = 1 << 20; for (int i = 2; i < n; ++i) { if (was[i]) continue; pr.push_back(i); for (int j = i; j < n; j += i) was[j] = 1; } } int upperb(i...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) throws IOException { (new Main()).solve(); } public Main() { } MyReader in = new MyReader(); PrintWriter out = new PrintWriter(System.out); void solve() throws IOException { //B...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; set<long long> SieveOfEratosthenes(int n) { bool prime[n + 1]; set<long long> pr; memset(prime, true, sizeof(prime)); for (long long p = 2; p <= n; p++) { if (prime[p] == true) { pr.insert(p); for (long long i = p * p; i <= n; i += p) prime[i] = fals...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int mx = 1000001; bool isPrime[mx]; vector<int> prime; void PrimeGenerator() { memset(isPrime, 1, sizeof(isPrime)); isPrime[0] = 0; isPrime[1] = 0; for (int i = 4; i < mx; i += 2) isPrime[...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.*; import java.util.*; public class CF { public static void main(String[] args) throws IOException { //FastScanner in = new FastScanner(new FileInputStream(new File("input.txt"))); //PrintWriter out = new PrintWriter(new File("output.txt")); FastScanner in = new FastScanner...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#pyrival orz import os import sys from io import BytesIO, IOBase input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
# specify list capacity MaxN = 101002 prime_list = [0 for x in range(MaxN)] prime_list[0] = prime_list[1] = 1 # mark all composite number with 1 for i in range(2, MaxN): if prime_list[i] == 1: continue j = i*2 while j < MaxN: prime_list[j] = 1 j += i # then replace all '0' and '1' with prime number i = Max...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; long long powermodm(long long x, long long n, long long M) { long long result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return result; } long long power(long long _a, long long _b) { long long _r = 1;...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nex...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
//package CF_166_Div_2; import java.io.*; import java.util.*; public class B implements Runnable{ public static void main(String args[]){ new B().run(); } // public static final String INPUT_FILE = "input.in"; // public static final String OUTPUT_FILE = "output.out"; @Overr...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int erat[(int)100010]; int s[505], r[505]; int main() { erat[1] = 0; erat[2] = 1; for (int i = 2; i < 100010; i++) { erat[i] = 1; } for (long long i = 2; i < 100010; i++) { if (erat[i] == 1) for (long long j = i * i; j < 100010; j += i) { era...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
# Matheus Oliveira limit = 110000 isPrime = [True] * limit isPrime[1] = False for i in xrange(2, limit): if(isPrime[i]): for j in xrange(i+i, limit, i): isPrime[j] = False def calculateAnswer(number): initial = number while(not isPrime[number]): number += 1 return (number - initia...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
# Author : nitish420 -------------------------------------------------------------------- import os import sys from io import BytesIO, IOBase from bisect import bisect_left def sieve(n): dp=[1]*(n+1) i=2 while i*i<=n: if dp[i]: for j in range(i*i,n+1,i): dp[j]=0 ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
def get_primes(n): primes = [] composite = set() for i in xrange(2, n + 1): if i not in composite: primes.append(i) composite.update(xrange(i * 2, n + 1, i)) return primes def bsearch(lst, n): l = 0 r = len(lst) while l < r: m = (l + r) / 2 if lst[m] < n: l = m + 1 else: ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
nearest_prime = [0] * 100004 def sieve(n): primes = [True] * (n + 1) primes[0] = False primes[1] = False for index, i in enumerate(primes): if i == True: for j in range(index * index, n + 1, index): primes[j] = False return primes def sub_from_nearest(a): re...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; bool prime[100005]; void pri1(int n) { memset(prime, 1, sizeof(prime)); int i, j; for (i = 2, prime[0] = prime[1] = 0; i < n; i++) { if (prime[i]) { for (j = 2; j < n && j * i <= 100005; j++) prime[j * i] = 0; } } } int main(void) { int a, b, ar[505]...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
n, m = map(int, input().split()) matrix = [[*map(int, input().split())] for _ in range(n)] MAX_ELEM = int(2e5) def sieve(): prime = [1] * MAX_ELEM i = 2 while i*i < MAX_ELEM: if prime[i]: j = 2 while i*j < MAX_ELEM: prime[i*j] = False j += 1 ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int N = 200000; 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;...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
limite = int(10e5) primos = [True for i in range(limite)] primos[0] = False primos[1] = False for i in range(2,limite): if primos[i]: for j in range(i**2, limite, i): primos[j] = False distancias = [0 for i in range(200000)] # distancias[0] = 2 # distancias[1] = 1 distancias[100000] = 3 for i i...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
from bisect import bisect_left M=10**5+10 p=[1]*M p[0]=p[1]=0 for i in range(2,M): if p[i]==1: for j in range(i+i,M,i): p[j]=0 prime=[] for i in range(len(p)): if p[i]==1: prime.append(i) #print prime[:10] n,m=map(int,raw_input().split()) a=[] d=[[0]*m for _ in range(n)] for _ in ran...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
limite = int(10e5) primos = [True for i in range(limite)] primos[0] = False primos[1] = False for i in range(2,limite): if primos[i]: for j in range(i**2, limite, i): primos[j] = False distancias = [0 for i in range(limite)] distancias[0] = 2 distancias[1] = 1 distancias[100000] = 3 base = int(...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; vector<int> getPrimeNumbers(int UPPER) { list<int> primeNumbers; for (int i = 2; i < UPPER; i++) { primeNumbers.push_back(i); } for (list<int>::iterator it = primeNumbers.begin(); it != primeNumbers.end(); ++it) { list<int>::iterator it1 = it; it1...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; using namespace std; long long sze = 1000010; vector<bool> v(sze, true); void preprocess() { v[0] = v[1] = false; for (long long i = 2; i * i < sze; i++) { if (v[i]) { for (long long j = i * i; j < sze; j += i) { v[j] = false; } } } } long ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int n, m; int a[505][505]; int vis[100005]; int b[100005]; int ans = 1e7; bool ss(int x) { if (x <= 1) return 0; for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) return 0; } return 1; } int main() { memset(vis, -1, sizeof(vis)); cin >> n >> m; int MAX ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.util.Scanner; public class A { public static boolean a[] = new boolean[100050]; public static void sieveAlgorithm() { for (int i = 2; i < a.length; i++) { a[i] = true; } boolean finished = false; for (int i = 2; i < a.length; i++) { // System.out.print...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import sys import math m,n = map(int,raw_input().split()) matrix_list = [] for i in range(m): matrix_list.append(map(int,raw_input().split())) def primesieve(n): bool_list = [] list_primes = [0] for i in xrange(n): bool_list.append(True) bool_list[0] = False bool_list[1] = False i=2 while i*i < n: if bool...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.util.ArrayList; import java.util.Scanner; public class Main{ public static boolean[] prime; public static int min; public static int getnext(int n){ while (prime[n]) { n++; } return n; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#!/usr/bin/env python3 # Takes INT for number up to which to calculate primes. # Returns 2 lists: list of primes and lists of flags corresponding to index of primes. def find_primes(prime_len): # Create a FLAG list of TRUE with length of values to search primes in. flag_list = [True]*(prime_len) # Ma...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> int prime[100001], mat[501][501]; void init() { int i, j; memset(prime, 0, sizeof(prime)); prime[0] = prime[1] = 1; for (i = 2; i * i < 100001; i++) { if (!prime[i]) { for (j = i * i; j < 100001; j += i) { prime[j] = 1; } } } j = 100003; for (i = 100000...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
// Author: Dr Jonathan Cazalas // Date: October 25, 2016 import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.Inp...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int n, m, a; int step[505][505]; int prime[100005]; void IsPrime() { int i; prime[0] = prime[1] = 0; prime[2] = 1; for (i = 3; i <= 100005; i++) prime[i] = i % 2 == 0 ? 0 : 1; int t = (int)sqrt(100005 * 1.0); for (i = 3; i <= t; i++) if (prime[i]) for ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int m, n; int a, x[510], y[510], d[100010]; bool z[100010]; int main() { z[1] = 1; for (int i = 2; i < 100010; i++) if (z[i] == 0) for (int j = 2; j * i < 100010; j++) z[j * i] = 1; for (int i = 100005; i >= 1; i--) { if (z[i] == 1) d[i] = d[i + 1]...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import math def prime(n): for i in xrange(3, n): if (n % i == 0): return False return True primes = [[1, -1] for i in xrange(100500)] primes[0] = [0, 2] primes[1] = [0, 1] for i in xrange(2, 318): if (prime(i)): j = 2 while (i*j < 100500): primes[i*j][0] = 0 j += 1 for i in...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
def rotated(array_2d): list_of_tuples = zip(*array_2d[::-1]) return list([list(elem) for elem in list_of_tuples]) 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: ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
# resubimit crivo = [True for i in xrange(1000000)] crivo[0] = crivo[1] = False for i in xrange(2, 1000000): if not crivo[i]: continue for j in range(i * i, 1000000, i): crivo[j] = False n, m = map(int, raw_input().split()) data = [] for i in xrange(n): data.append(map(int, raw_input().sp...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import math def findPrime (arr) : largest = 100003 for index in range(100000,1,-1): isPrime = True root = math.floor(math.sqrt(index)) for div in range(2,root+1) : if index%div == 0 : isPrime = False arr[index] = largest break ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.*; import java.util.StringTokenizer; public class PrimeMatrix { static boolean esPrimo[] = new boolean[100000 + 100]; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); criba(100090); S...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int N = 505; int n, m, a[N][N]; int main() { ios::sync_with_stdio(false); cin >> n >> m; set<int> st; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j]; for (int i = 2; i <= 2 * 100005; i++) { int z = i; for (int j = 2; j * j...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int main() { int primes[200010]; vector<int> primesList; int maze[505][505]; int n, m, t; memset(primes, 0, sizeof(primes)); for (int i = 2; i * i <= 200000; i++) { if (primes[i] == 1) continue; for (int j = i * i; j <= 200000; j += i) { primes[j] ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import time primes = list() def generate_primes(): a=[0]*100010 for x in xrange(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...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import bisect top = 10**5+10 pos = [True] * top for i in range(2, top): if pos[i]: for j in range(2*i, top, i): pos[j] = False primes = [i for i in range(2, top) if pos[i]] n, m = map(int, input().split()) rows = [0] * n cols = [0] * m for i in range(n): row = list(map(int, input().split())) for j in range(...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import math # LINK FOR PROBLEM: http://codeforces.com/problemset/problem/271/B ## CRIVO m = 10 ** 5 + 10 eh_primo = [True] * m eh_primo[0] = False eh_primo[1] = False for i in xrange(int(math.sqrt(m))): if eh_primo[i]: for j in xrange(i * i, m, i): eh_primo[j] = False n, m = map(int,...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import java.io.*; public class taskB { private static final int mx =1000000; private static final long l=1000000000; private static boolean primes[]=new boolean[mx+1]; private static void Eratos() { Arrays.fill...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
/** * @author Juan Sebastian Beltran Rojas * @mail jsbeltran.valhalla@gmail.com * @veredict No enviado * @problemId CF166B.java * @problemName CF166B.java * @judge http://www.spoj.pl | http://uva.onlinejudge.org/ | http://livearchive.onlinejudge.org/ * @category --- * @level ??? * @date 11/02/2013 **/ import ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.InputStreamReader; import java.io.IOException; import java.util.Arrays; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Vai...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e18; const long long int mod = 998244353; bool sortbysec(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { return (a.second < b.second); } signed main() { ios_base::sync_with_stdio(false...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import static java.lang.Math.*; import static java.util.Arrays.*; import java.util.*; import java.io.*; public class Main { int N = 100100; int INF = 1<<28; boolean[] p; int[] dp; void prime() { p = new boolean[N]; dp = new int[N]; fill(dp, 10000); for(int i=2;...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
from bisect import bisect l=lambda:map(int,raw_input().split()) # p=[2,3] # [p.append(i) for i in range(5,10**5+10,2) if all([i%x for x in p])] p=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500 + 10; const int MAXP = 1e5 + 100; bool prime[MAXP]; void initPrime() { memset(prime, true, sizeof(prime)); prime[0] = prime[1] = false; for (int i = 2; i < MAXP; ++i) { if (prime[i]) { for (int j = i + i; j < MAXP; j += i) { prim...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int prime[100004]; void sieve() { prime[1] = 1; for (int i = 4; i < 100004; i += 2) prime[i] = 1; int root = sqrt(100004); for (int i = 3; i <= root; i += 2) { if (prime[i] == 0) { for (int j = i * i; j < 100004; j += i * 2) { prime[j] = 1; }...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 5; int n, m, t[550][550], ans = 2e9, vis[M]; vector<int> p; void pre() { for (int i = 2; i < M; i++) { if (!vis[i]) { p.push_back(i); for (int j = i + i; j < M; j += i) vis[j] = 1; } } } int main() { pre(); cin >> n >> m; fo...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
primes = [] isPrime = [True for i in range(10**5 + 7)] nextPrime = [] #crivo isPrime[1] = isPrime[0] = False for i in range(2, 10**5 + 7): if isPrime[i] == True: primes.append(i) for j in range(i * i, 10**5 + 7, i): isPrime[j] = False aux = 0 for i in range(10**5 + 1): ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import copy from bisect import bisect_left primes = [] def sieve(): M = int(1e6) prime = [True for i in range(M + 1)] p = 2 while p * p <= M: if prime[p]: for i in range(p * 2, M + 1, p): prime[i] = False p += 1 prime[0] = False prime[1] = False ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import static java.lang.Math.*; import static java.lang.reflect.Array.*; import static java.util.Arrays.*; import java.io.*; import java.lang.reflect.*; import java.util.*; public class B { final int MOD = (int)1e9 + 7; final double eps = 1e-12; final int INF = (int)1e9; public B () { int N = sc.nextInt(); ...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
N_MAX = (10**5 + 7) N, M = 0, 0 matrix = [[]] closest_prime = [[]] prime = [True] * N_MAX ## Sieve of Eratosthenes def sieve(): global prime global closest_prime prime[0] = False prime[1] = False closest_prime = [0] * N_MAX def backtrack(value): closest_prime[value] = value f...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); } void online_judge() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } const int flag_max = 0x3f3f3f3f; const long long OO = 1e9; const double EPS = (1e-7); int dcmp(d...
Problem: You've got an n Γ— m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public final class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); ...