PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000032. Tổng phần dư lớn nhất (Modulo Summation)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng phần dư lớn nhất (Modulo Summation)
Modulo Summation
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers , define for any nonnegative integer . Find the maximum possible value of ; you need not output .
Input
First line: . Second line: values .
Output
Print the maximum possible value of .
Subtasks
- Subtask 1 (20 points): ;
- Subtask 2 (30 points): ;
- Subtask 3 (50 points): ;
Examples
Input
3
3 4 6
Output
10
Explanation
For , the remainders modulo are , summing to , the sum of their individual maxima.