Project Euler #13: Large sum

Sort by

recency

|

157 Discussions

|

  • + 0 comments

    Python3

    if name == 'main':

    T = int(input())
    total_sum = 0
    
    for _ in range(T):
        n = int(input())
        total_sum += n
    
    
    print(str(total_sum)[:10])
    
  • + 0 comments

    Java8 code

    import java.io.*;
    import java.util.*;
    import java.math.BigInteger;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
            int testcases = s.nextInt();  // Number of test cases
            BigInteger sum = BigInteger.ZERO;
    
            // Summing up all the large numbers
            for (int i = 0; i < testcases; i++) {
                String num = s.next();  // Read the number as a string
                sum = sum.add(new BigInteger(num));  // Add to the sum using BigInteger
            }
    
            // Convert the sum to a string and print the first 10 digits
            String result = sum.toString();
            System.out.println(result.substring(0, 10));
        }
    }
    
  • + 0 comments

    100% python

    n = int(input())
    ans = 0
    for _ in range(n):
        num = int(input())
        ans += num
    
    print(str(ans)[:10])
    
  • + 0 comments
    function processData(input) {
        const [n, ...number] = input.split('\n').map(BigInt)
        
        let result = BigInt(0);
        for(let i = 0; i<n; i++) {
            result +=BigInt(number[i])
        }
        
        console.log(result.toString().substring(0, 10))
    {
        
    } 
    
  • + 0 comments

    Python 3

    inputs = [int(input()) for _ in range(int(input()))]
    print(str(sum(inputs))[:10])