Sieve Game
시간 제한1초메모리 제한1024 MB
고른 번호의 배수 위치를 모두 1만큼 늘리거나 줄이는 연산으로 영 배열을 주어진 목표 배열로 바꾸는 최소 연산 횟수를 구한다.
문제
Alice, after mastering the sieve of Eratosthenes, excitedly created a puzzle game that made use of it.
The rules of the puzzle game are as follows:
-
An array is given where all is initially .
-
A target array is given. Her goal is to make for all .
-
Each time, she can perform one of the following two operations:
- Choose and increase by for every that is a multiple of .
- Choose and decrease by for every that is a multiple of .
-
She can repeat this process as much as she wants.
Alice aims to solve the puzzle using the fewest operations, showcasing her puzzle-solving skill. Please help Alice find the minimum number of operations to solve the puzzle.
입력
The first line contains one integer, .
The second line contains space-separated integers — elements of the array .
출력
Print out the minimum number of operations to solve the puzzle. If the puzzle is unsolvable, print -1.
제한
- All values in the input are integers.