prompt
string
response
string
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
n = int(input()) x = [i for i in range(2, n + 2)] x[n - 1] = 1; if(n < 3): print(-1) else: for v in x: print(v, end =' ')
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
n = int(input()) if n == 1 or n == 2: print(-1) else: arr = [x for x in range(2, n+1)] arr.append(1) print(*arr)
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
#include <bits/stdc++.h> using namespace std; bool com(pair<int, int> x, pair<int, int> y) { if (x.first == y.first) return x.second < y.second; return x.first < y.first; } long long int power(long long int x, long long int y) { long long int prod = 1; while (y) { if (y & 1) prod = (prod * x) % 1000000007; ...
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n < 3) { cout << -1; } else { for (int i = (int)0; i < (int)n; i++) { cout << n - i << " "; } } return 0; }
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
#include <bits/stdc++.h> int main() { int i, j, n, a[105]; for (i = 1; i <= 100; i++) a[i] = 1; a[1] = 3; a[2] = 2; scanf("%d", &n); if (n <= 2) printf("-1\n"); else for (i = 1; i <= n; i++) printf("%d ", a[i]); return 0; }
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; if (n == 1 || n == 2) cout << -1; else for (int i = n; i >= 1; i--) cout << i << " "; return 0; }
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
__autor__ = 'Esfandiar' n = int(input()) if n < 3:print(-1);exit() print(5,4,end=" ") for i in range(n-2):print(1,end=" ")
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
n = int(input()) if n <= 2: print(-1) else: ans = [3, 2, 1] + [1] * (n - 3) print(*ans)
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
n = int(input()) if n == 1 or n == 2: print(-1) else: for I in range(n, 0, -1): print(I, end = " ") print()
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
n=int(input()) if(n<=2): print(-1) else: for i in range(n,1,-1): print(i,end=" ") print(1)
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
n = int(input()) if (n <= 2): print(-1) else: for i in range(n): print(n-i, end = ' ')
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
import java.util.*; import java.io.*; import java.math.*; public class Main{ public static void main(String []args)throws IOException{ //BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); Scanner input = new Scanner(System.in); PrintWriter pw = new PrintWriter(new OutputStreamWriter...
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
import java.util.*; public class BuggySorting { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); if (n < 3) { System.out.print(-1); System.exit(0); } for (int i = n; i > 0; i--) { System.out.print(i + " "); } cin.close(); } }
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
n = int(raw_input()) if n < 3: print -1 else: for i in range(n, 0, -1): print i,
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 2) cout << -1; else { while (n) { cout << n << " "; n--; } } return 0; }
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n <= 2) cout << -1 << endl; else for (int i = n; i > 0; i--) cout << i << " "; cout << endl; return 0; }
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
n=eval(input()) a="" if n==1 or n==2 : print (-1) else: i=0 j=100 while i<n : a+= str(j) a+=" " i+=1 j-=1 print (str(a))
Problem: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The ...
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; public class newsort { public static void main(String args[]) throws IOException { BufferedReader cin=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(cin.readLine()); /*String s=cin.readLine(); ...
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 comp(int a, int b) { return (a < b); } int main() { long long int s = 100010; bool a[s]; memset(a, true, s); a[1] = false; for (int i = 2; i * i < s; i++) { if (a[i]) { for (int j = i + i; j < s; j += i) a[j] = false; } } long long int m, 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...
# coding: utf-8 matrix_params = input() params = matrix_params.split(" ") rows = int(params[0]) cols = int(params[1]) initial_matrix = [] count_r = [] count_c = [] curr_row = [] def is_prime(n): if n <= 3: return n > 1 if n % 2 == 0 or n % 3 == 0: return False i = 5 while i ** 2 <= n: if n % i == ...
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[600][600], r[600], c[600], pr[111118]; int check[111118]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } for (int i = 1; i <= 111111; i++) { check[i] = 1; } check[1] = 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 java.lang.*; import java.io.*; import java.util.*; public class Matrix { public static void main(String[] args) throws java.lang.Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(o...
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 { void solve() throws IOException { boolean[] p = new boolean[200010]; Arrays.fill(p, true); List<Integer> primes = new ArrayList<>(p.length); for (int i = 2; i < p.length; i++) { if (p[i]) { p...
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> const long double eps = 1e-12; using namespace std; vector<long long int> primes; long long int p[1000001]; void primeSeive() { long long int n = 1000001; p[0] = p[1] = 0; p[2] = 1; for (long long int i = 3; i <= n; i += 2) { p[i] = 1; } for (long long int i = 3; i <= n; 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...
max = 150035 primes = [0 for x in range(max)] def sieveOfEratosthenes(): primes[1] = primes[0] = 1 for i in range(2, max): if primes[i] == 0: for j in range(i + i, max, i): primes[j] = 1 for i in range(max-2, -1, -1): if (primes[i] != 0): primes[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.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...
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 B; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Solution { BufferedReader br; StringTokenizer st; int n, m, pn; int[][] a; int[] p = new int[222222]; boolean[] pri...
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> const int LI = 100005; using namespace std; int isprime[LI + 10]; int main() { int n, m; int t[502][502], sl[502] = {0}, sc[502] = {0}, tbs[502][502], minl, minc; vector<int> prime; for (int i = 2; i < LI; i++) { if (isprime[i] == 0) { for (long long j = i + i; j < LI; j += 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Main4 { public static void main(String a[]) throws IOException { BufferedReade...
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 Main { public static void main(String[] args) { FastScanner in = new FastScanner(System.in); int N = in.nextInt(); int M = in.nextInt(); int[][] mat = new int[N+1][M+1]; for (int i = 1; i <=N; i++) for (int j = 1; j <= M; j++) { int p = in.nextIn...
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...
rows,cols = map(int,input().split()) a = [] for i in range(rows): a.append([]) k = list(map(int,input().split())) a[i]+=k primes = [True for i in range(100004)] for num in range(2,50003): for i in range(num+num,100004,num): primes[i]=False primes[0]=2 primes[1]=2 primes[2]=2 for num 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...
ncrivo = int(10e5) crivo = [True for i in range(ncrivo)] crivo[0] = False crivo[1] = False for i in range(2, ncrivo): if crivo[i]: for j in range(i ** 2, ncrivo, i): crivo[j] = False # frequencia contador = [0 for i in range(200000)] contador[100000] = 3 for i in range(99999, -1, -1): if c...
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 genSieve(): n = 200000 isPrime = [True for i in range(n)] isPrime[0] = isPrime[1] = False for i in range(2,n): j = i while i*j < n: isPrime[i*j] = False j += 1 return isPrime isPrime = genSieve() def distToPrime(n): dist = 0 while True: if...
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.*; 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...
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.math.BigInteger; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; im...
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...
import java.io.IOException; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.MathContext; import java.text.DecimalFormat; import java.util.*; public class contest { public static boolean isPrime(int n) { if(n==2)return true; if(n==3)return true; for(int i=2;i<Math.sqrt(n)+1;i++) { if...
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 ArrayList<Integer> sieve(int n){ boolean[] primeBoolArray = new boolean[n+1]; Arrays.fill(primeBoolArray, true); ArrayList<Integer> myPrimes = new ArrayList<Integer>(n+1); primeBoolArray[0] = false; primeBoolArray[1] = false; for(int currNumber = ...
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.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; import java.util.*; public class CF271B { public static void main(String[] args) { FastReader input = new FastReader(); ...
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 org.omg.CORBA.MARSHAL; import java.io.*; //import java.lang.reflect.Array; import java.lang.reflect.Array; import java.util.*; //import java.util.logging.LoggingMXBean; public class citylights { public static int[] arr; public static ArrayList<Integer> p; public static int[] val; public 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; long long int sieve[1000000], large[1000000]; int main() { long long int n, m, max = 0, i, j, cou = 0; cin >> n; cin >> m; vector<vector<long long int> > v(n, vector<long long int>(m)); for (i = 0; i < n; i = i + 1) { for (j = 0; j < m; j = j + 1) { cin ...
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 = 1e5 + 100; bool primes[N]; int rows[505]; int cols[505]; int main() { memset(primes, true, N); memset(rows, 0, 505); memset(cols, 0, 505); primes[0] = primes[1] = false; for (int i = 2; i * i < N; i++) if (primes[i]) for (int j = i * 2; 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; void sieve(); int binser(int, int, int); vector<int> prime; int main() { sieve(); int n, m; cin >> n >> m; int num[n][m]; int co = 0, re = 1e9; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> num[i][j]; int x = binser(num[i][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...
def primo(p): ret = [True] * p ret[0] = False ret[1] = False for i in range(2,p): if ret[i]: j = i * i while True : if j >= p : break ret[j] = False j += i return ret v = 10**5+10 primo = primo(v) aux = [0,1,0] for i in range(3,v): cont = 0 if not(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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; public class practic { public static void main(String[] args) throws IOException { boolean[] isnotprime = new boolean[110001]; isnotprime[0] = true; ...
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())) list_primes = [0] def is_prime(n): if n == 2 or n == 3: return True elif n < 2 or n % 2 == 0: return False elif n < 9: return True ...
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() { long long is[110005]; for (long long i = 2; i < 110005; i++) { if (is[i] == 0) { for (long long j = i * i; j < 110005; j += i) { is[j] = 1; } } } long long x; map<long long, long long> p; is[1] = 1; for (long long 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...
#include <bits/stdc++.h> using namespace std; int pr[200000], pi; int vis[200000]; void civ() { int i, j; pr[pi++] = 2; vis[1] = vis[0] = 1; for (i = 4; i < 110000; i += 2) vis[i] = 1; for (i = 3; i < 110000; i += 2) { if (!vis[i]) { pr[pi++] = i; if (i < 1000) { for (j = i * i; j < 11...
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.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String [] args ) { try{ 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 double PI = atan(1) * 4; const int mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; while (tt--) { int sieve[100010]; for (int i = int(0); i < int((100010) + 1); ++i) sieve[i] = i; set<int> st; for (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 bisect def b_s(dp,ele): l=0;r=len(dp)-1;ans=0 while l<=r: mid=(l+r)//2 if dp[mid]==ele:return mid elif dp[mid]>ele:ans=mid;r=mid-1 else:l=mid+1 return ans def sieve(n): dp=[True]*(n+1);i=2;dp[0]=False;dp[1]=False;dp[2]=True while i*i<=n: j=i for ii in range(j*j,n+1,j): dp[ii]=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...
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> primes; long long const N = 1e5 + 20; bool v[N]; void sieve() { v[0] = v[1] = 1; for (int i = 2; i < N; i++) { if (!v[i]) { primes.push_back(i); for (int j = i * 2; j < N; j += i) { v[j] = 1; } } } } int main() {...
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_filter(n,isPrime): for i in range(2,int(math.sqrt(n))+1): if isPrime[i]: for j in range(i*i,n+1,i): isPrime[j]=False return isPrime def minStep(matrix,nextPrime): cols = [0 for i in range(len(matrix[0]))] rows = [0 for i in range(len(matrix))] for r in range(len(matrix)): for c ...
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...
num = 100100 primes = [0]*num primes[1] = 1 for i in range(2,num): if primes[i] == 0: for j in range(2*i,num,i): primes[j] = 1 cur = 0 index = num - 1 while index > 0: if primes[index] == 0: primes[index] = index cur = index else: primes[index] = cur index -= 1 matrix = [] [n, m] = 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...
import java.util.*; import java.io.*; public class PrimeMatrix { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); boolean[] isPrime = new boolean[1000000]; for(int x = 2; x < isPrime.length; x++) { isPrime[x] = true; } ...
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.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; import java.io.*; public class Contest1 { static Scanner sc=new Scanner(System.in); static PrintWriter out=new PrintWriter(System.out); 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...
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())) ''' list_primes = [0] def is_prime(n): if n == 2 or n == 3: return True elif n < 2 or n % 2 == 0: return False elif n < 9: return True...
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 Main { static boolean[] bol = new boolean[100010]; static int[] primes = new int[9593]; private static void init() { for(int i=2;i*i<100010;i++) { if(!bol[i]) { for(int j=i+i;j<100010;j+=i) { bol[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; using vi = vector<int>; using pi = pair<int, int>; using ll = long long int; template <typename T1, typename T2, typename T3> T1 modpow(T1 _a, T2 p, T3 mod) { assert(p >= 0); ll ret = 1, a = _a; if (a < 0) { a %= mod; a += mod; } if (a >= mod) { a %= 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 bisect import math def chk_prime(x): for i in xrange(2,int(math.sqrt(x))+1): if x % i == 0: return False return True v = [] for x in xrange(2,100007): if chk_prime(x): v.append(x) n,m = map(int,raw_input().split()) g = [] for _ in xrange(0,n): g.append(map(int,raw...
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 def primer(): n = 100010 li = [True for i in range(n)] li[0] = False li[1] = False prime = [] for i in range(2, n): if li[i]: prime.append(i) for j in range(2,n): if i*j >= n: break li[i*j] = False return prime def main(): res = 987654321987 prime = primer() 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...
from math import sqrt, ceil n, m = list(map(int, raw_input().split(' '))) def find_primes(): maxi = 10**5 + 10 primes = [True] * (maxi + 1) primes[0] = False primes[1] = False i = 2 while i * i <= maxi: if primes[i]: for j in range(i**2, maxi+1, i): primes[...
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.IOException; import java.util.Arrays; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void...
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 primes=[2,3,5,7,11,13,17,19,23,29, 31,37,41,43,47,53,59,61,67,71, 73,79,83,89,97,101,103,107,109,113, 127,131,137,139,149,151,157,163,167,173, 179,181,191,193,197,199,211,223,227,229, 233,239,241,251,257,263,269,271,277,281, 283,293,307,311,313,317,331,337,347,349, 353,359,367,373,379,383,389,397,401,409,...
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 pc, notPrime[3130], P[10000], A[502][502], B[502][502]; void sieve(int n) { int i, j; (notPrime[1 >> 5] |= (1 << (1 & 31))); for (j = 2 * 2; j <= n; j += 2) (notPrime[j >> 5] |= (1 << (j & 31))); for (i = 3; i * i <= n; i += 2) if ((!(notPrime[i >> 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...
n,m=map(int,raw_input().split()) N=int((10**5)+100) r,c=[0]*n,[0]*m a=[0]*2+[1]*N for i in xrange(2,N): if (a[i]): for j in xrange(2,1+(N/i)):a[i*j]=0 for i in reversed(xrange(1,N)): if (a[i]):a[i]=i else:a[i]=a[i+1] for i in xrange(n): s=map(lambda x:a[x]-x,map(int,raw_input().split())) 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; const long long mod = 1000000007; const long long N = 200005; vector<long long> vis(N); vector<vector<long long>> adj(N); void dfs(long long v) { vis[v] = 1; for (auto i : adj[v]) { if (!vis[i]) { dfs(i); } } return; } bool isPrime(long long n) { if ...
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 a[600][600]; int b[600][600]; bool IP[1000000]; int F(int x) { int tmp = x; while (true) { if (IP[x] == true) { return x - tmp; } x++; } } int main() { ios_base::sync_with_stdio(false); for (int i = 2; i <= 1000000; i++) IP[i] = true; 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...
primes = [True]*(2*(10**5) + 1) for i in range(2,int((2*(10**5) + 1)**0.5 + 1)): if primes[i]: for j in range(2*i,len(primes),i): primes[j] = False primes = [i for i in range(2,len(primes)) if primes[i]] def bin_search(n): l = 0 r = len(primes) while l <= r: mid = (l+r)//2 if primes[mid] == n: 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...
import sys inp = [[int(j) for j in i.split(' ')] for i in sys.stdin.read().strip().splitlines()[1:]] def check(m): return min([sum([rest[i] for i in s]) for s in m]) sieve = [None]*100005 sieve[0] = False sieve[1] = False for i in xrange(2, 100005): if sieve[i] == None: sieve[i] = True 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 java.util.Scanner; public class C5 { private static boolean[] calculosPrimos(int size) { boolean arreglo[]; arreglo = new boolean[size + 1]; for (int i=2; i<size; i++) { arreglo[i] = true; } for (int j=2; j<=size; j++) { if (arreglo[j] == true) { for (int k=2; k<=(size)/j; k++ ) arre...
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 = 2 * 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...
#include <bits/stdc++.h> int abs(int a) { if (a < 0) return -1 * a; return a; } int big(int a, int b) { if (a > b) return a; return b; } int small(int a, int b) { if (a < b) return a; return b; } int compare(const void *a, const void *b) { int *p1 = (int *)a; int *p2 = (int *)b; return *p1 - *p2; } 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...
#include <bits/stdc++.h> using namespace std; template <typename T> T sgn(T x) { return x < 0 ? -1 : x != 0; } template <typename T> T gcd(T a, T b) { return a ? gcd(b % a, a) : b; } void reads(string& x) { char kk[((long long)5e2 + 123)]; scanf("%s", kk); x = kk; } long long n, m, ans; long long v, r[((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...
import java.util.*; /** * Created by shereifhawary on 1/9/16. */ public class PrimeMatrix { private static List<Integer> primes; public static void main(String... args) { primes = new ArrayList<Integer>(); buildPrimes(primes); Scanner scanner = new Scanner(System.in); 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...
n, m = tuple(map(int, input().split())) pro = [list(map(int, input().split())) for _ in range(n)] r = [0] * (10**5+4) r[1] = 1 for i in range(2, 10**5+4): if r[i] == 0: j = 2 while (i * j < 10**5+4): r[i * j] = 1 j += 1 r[-1] = len(r) - 1 for i in range(10**5+2, 0, -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 sys,math,bisect inf = float('inf') mod = (inf)+7 def lcm(a,b): return int((a/math.gcd(a,b))*b) def gcd(a,b): return int(math.gcd(a,b)) def binarySearch(a,x): i = bisect.bisect_left(a,x) if i!=len(a) and a[i]==x: return i else: return -1 def lowerBound(a, x): i = bisect.bis...
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 primeNumberList = [True for i in range(limit + 1)] #Coloca true em todo mundo distanceToNextPrimeNumber = [0 for i in range(200000)] def sieve(): primeNumberList[0] = primeNumberList[1] = False #0 e 1 não sao primos, logo, coloca false for i in range(2, int(mat...
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...
R = 10 ** 5 + 300 is_prime = [0] * (R + 1) is_prime[1] = 1 d = 2 while d * d <= R: if not is_prime[d]: for i in range(d ** 2, R + 1, d): is_prime[i] = 1 d += 1 for i in range(R + 1): if is_prime[i]: k = i step = 0 while k <= R and is_prime[k]: 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.io.*; import java.util.Arrays; public class primeMatrix { static boolean []primes=new boolean[1000000]; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s[]=br.readLine().split(" "); ...
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 Queue import * # Queue, LifoQueue, PriorityQueue from bisect import * #bisect, insort from datetime import * from collections import * #deque, Counter,OrderedDict,defaultdict import calendar import heapq import math import copy import itertools myread = lambda : map(int,raw_input().split()) def solver(): 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...
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { int i; if (n == 1 || n == 0) return false; for (i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } int main() { int i = 0, j = 0, k = 0, l = 0, temp; int primes[100004]; for (i = 100003; i >= 0; i--) { if (...
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.*; import java.math.*; public class Main{ static BufferedReader bf; static PrintWriter out; static FastScanner in; static final int MAXN = (int)1e6 + 100; static final int INF = Integer.MAX_VALUE; static boolean used [] = new boolean[MAXN]; static int a[][] = new int[555][55...
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 sys import stdin,stdout input=stdin.readline import math,bisect num = 102001 numD = 2 prime=[1]*num prime[1]=0 prime[0]=0 for i in range(numD,num): j=i while(j+i<num): j+=i prime[j]=0 l=[] n,m=map(int,input().split()) for i in range(n): t=list(map(int,input().split())) l.append(t...
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 primes(l): z=[1]*l z[:2]=[0,0] for (i,p) in enumerate(z[2:],2): if p: z[i*i::i]=[0]*((l-i*i)/i+(l%i!=0)) return z p=primes(10**5+100) e=[0]*len(p) j=len(p) for i in range(len(p) - 1, 0, -1): if p[i]: j = i e[i] = j - i r=lambda: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 java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int x = input.nextInt(); int y = input.nextInt(); int[][] a = new int[x][y]; int minc =10000000; for(int i =0;i<x;i++){ for(int j=0;j<y;j++ ){ a[i][j]=input.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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; import java.util.TreeSet; public class primematrix { static TreeSet<Integer> primes; static int[] isComposite; static void sieve(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...
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.math.BigInteger; import java.util.*; import java.text.*; public class cf271b { static BufferedReader br; static Scanner sc; static PrintWriter out; public static void ini...
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 javax.swing.*; import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) throws IOException { //BufferedReader reader=new BufferedReader(new FileReader("input.txt")); ...
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 n, m, primes[200005] = {0}; long long grid[505][505], movesReq[505][505] = {0}; int32_t main() { cin >> n >> m; primes[0] = 1; primes[1] = 1; for (long long i = 2; i * i <= 200000; i++) if (!primes[i]) for (long long j = 2; i * 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 sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect 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...
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...
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Apr 20 17:10:13 2020 @author: narayanaaramamurthy """ n,m=map(int,input().split()) c=100030 f=[0]*c f[1]=1 for i in range(2,c): if f[i]==0: for j in range(i+i,c,i): f[j]=1 t=0 for i in range(c-1,0,-1): if f[i]==0: ...
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 matrix[505][505]; int m, n; int col[505]; int row[505]; int prime[110000]; int pc; bool visit[110000]; void init() { for (int i = 2; i < 110000; i++) { if (visit[i]) continue; for (int j = i * 2; j < 110000; j += i) visit[j] = true; } for (int i = 2; 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...
p=10**5+10 def sieve(): l=[True]*p i=2 while i*i<=p: if l[i]: for j in range(i*i,p,i): l[j]=False i+=1 primes=[] for i in range(2,p): if l[i]: primes.append(i) return primes primes=sieve() from bisect import bisect_left as bl 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...
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase from bisect import bisect_left as bl #c++ lowerbound bl(array,element) from bisect import bisect_right as br #c++ upperbound br(array,element) primes=[2] import math def getprime(): global primes for x in rang...
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; long long ans = 1000000007; int v[505][505]; int vis[1000005]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int h = 1; h <= m; h++) cin >> v[i][h]; for (int i = 3; i <= 1000000; i += 2) if (!vis[i]) for (int h = i * 3; h <= 100...
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): #(limit-i*i)//i+1) gives number of multiples of i to given range l[i*i::i]=[1]*((limit-i*i)//i +1)#floor division i , +1 #in l we have 0 values at prime places for i in range(limit,-1,-1): l[i]*=l[i+1]+1 #minimum numbe...
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.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class CF271B { static BufferedReader __in; static PrintWriter __out; static StringTokenizer input; public static void main(String[] args) throws IOException { __in = new BufferedRead...
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.BufferedWriter; import java.io.DataInputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator;...