/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 13ms 3.02 MiB
#2 Wrong Answer 14ms 3.098 MiB

Code

import sys

def solve():
    """
    Solves a single test case for the arithmetic sequence sum problem.
    """
    try:
        s = sys.stdin.readline().strip()
        n = int(sys.stdin.readline())
    except (IOError, ValueError):
        # Stop if there's no more input
        return False

    # Clean up the string to extract the numbers
    # We only need the first number, which is the start of the sequence
    parts = s.replace('+', ' ').replace('...', ' ').split()
    
    if not parts:
        # Handle cases with empty or malformed strings gracefully
        return True

    # The first term of the arithmetic progression
    first_term = int(parts[0])
    
    # The number of terms is N
    num_terms = n
    
    # The common difference is 1 for consecutive numbers
    difference = 1

    # Using the formula for the sum of an arithmetic series:
    # Sum = n/2 * (2*a + (n-1)*d)
    # Since n can be large, we should use integer arithmetic that avoids floats
    # by calculating (n * (2*a + (n-1)*d)) // 2
    sum_val = (num_terms * (2 * first_term + (num_terms - 1) * difference)) // 2
    
    print(sum_val)
    return True

def main():
    """
    Main loop to handle all test cases from stdin.
    """
    while solve():
        pass

if __name__ == "__main__":
    main()

Information

Submit By
Type
Submission
Problem
P1231 Busy Friend
Contest
Testing - Intra LU Programming contest 25
Language
Python 3 (Python 3.12.3)
Submit At
2025-08-30 20:25:53
Judged At
2025-08-30 20:25:53
Judged By
Score
0
Total Time
14ms
Peak Memory
3.098 MiB