oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

trifish Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

trifish.html

Problem Description

In certain areas of the world, there are triangular fishies. Rar the Cat has recently caught a triangular fish of size N and he has noticed that he has numbers on it.

A triangle fish of size N has N rows of numbers. The ith row has i numbers, numbered ascendingly from 1 to i.

For example, a fish of size 5 has the following numbers:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Rar the Cat wants to know the sum of all the numbers on the triangular fish. However, as this number can be very big, he wants to know the remainder when that sum is divided by M. (Sum mod M)

Input

The input will contain 2 integers, N followed by M, on a single line.

Output

Print the sum of the numbers on the triangular fish with size N

Limits

0 < M ≤ 5000000

Subtasks

Subtask 1 (23 marks): 0 < N ≤ 5000

Subtask 2 (32 marks): 0 < N ≤ 5000000

Subtask 3 (45 marks): 0 < N ≤ 2000000000

Subtask 4 (0 marks): Sample Testcases

Sample Input 1

5 100

Sample Output 1

35

Sample Input 2

5 7

Sample Output 2

0

Sample Input 3

5 10

Sample Output 3

5

Tags

Number Theory

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
123500.5s16MBMinimum
232500.5s16MBMinimum
345500.5s16MBMinimum
4030.5s16MBMinimum

Judge Compile Command

g++-8 ans.cpp -o trifish -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.