B - 9x9 Sum
Source: atcoder
Difficulty: 150

Problem Statement
Among the
81
integers that appear in the
9
-by-
9
multiplication table, find the sum of those that are not
X
.
There is a grid of size
9
by
9
.
Each cell of the grid contains an integer: the cell at the
i
-th row from the top and the
j
-th column from the left contains
i \times j
.
You are given an integer
X
. Among the
81
integers written in this grid, find the sum of those that are not
X
. If the same value appears in multiple cells, add it for each cell.
Constraints
X
is an integer between
1
and
81
, inclusive.
Input
The input is given from Standard Input in the following format:
X
Output
Print the sum of the integers that are not
X
among the
81
integers written in the grid.
Sample Input 1
1
Sample Output 1
2024
The only cell with
1
in the grid is the cell at the 1st row from the top and 1st column from the left. Summing all integers that are not
1
yields
2024
.
Sample Input 2
11
Sample Output 2
2025
There is no cell containing
11
in the grid. Thus, the answer is
2025
, the sum of all
81
integers.
Sample Input 3
24
Sample Output 3
1929

C++ solution:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int a;
  cin >> a;
  int sum = 0;
  
  for(int i = 1; i <= 9; i++){
    for(int j = 1; j <= 9; j++){
      if(i*j != a)sum += i*j;
    }
  }
  cout << sum << endl;
}

Go solution:
package main

import (
	"fmt"
	"strings"
	"os"
	"bufio"
	"strconv"
)

func main() {
	fmt.Println(q2())
}

func q1() int{
	sc:=bufio.NewScanner(os.Stdin)
	var m, n int

	sc.Scan()
	input:=strings.Split(sc.Text()," ")
	m, _ = strconv.Atoi(input[0])
	n, _ = strconv.Atoi(input[1])

	return (m+n)*(m+n)
}

func q2() int{
	sc:=bufio.NewScanner(os.Stdin)

	sc.Scan()
	x,_:=strconv.Atoi(sc.Text())
	sum:=2025

	for i:=1;i<=9;i++{
		for j:=1;j<=9;j++{
			if i*j==x{
				sum-=i*j
			}
		}
	}
	return sum
}

Java solution:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();

        int x = sc.nextInt(), sum = 0;

        for (int i=1;i<=9;i++) {
            for (int j=1;j<=9;j++) {
                if (i*j != x) sum += i*j;
            }
        }

        System.out.println(sum);
    }

    public static class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

JavaScript solution:
function Main(input) {
	const inp = input.split("\n");
	var X=Number(inp[0])
	var result=0;
	for(var i=1;i<=9;i++){
	  for(var j=1;j<=9;j++){
	    if(j*i!=X){
	      result+=i*j
	    }
	  }
	}
	console.log(result)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Python solution:
x = int(input())
ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        if i * j == x:
            continue
        ans += i * j
print(ans)

Ruby solution:
x = gets().to_i
total = 0
(1..9).each do |i|
    (1..9).each do |j|
        curr = i * j
        if curr != x
            total += curr
        end
    end
end

puts total