Problem:
Score : 200 points

Problem Statement

Let us define the FizzBuzz sequence a_1,a_2,... as follows:

If both 3 and 5 divides i, a_i=\mbox{FizzBuzz}.

If the above does not hold but 3 divides i, a_i=\mbox{Fizz}.

If none of the above holds but 5 divides i, a_i=\mbox{Buzz}.

If none of the above holds, a_i=i.

Find the sum of all numbers among the first N terms of the FizzBuzz sequence.

Constraints

1 \leq N \leq 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the sum of all numbers among the first N terms of the FizzBuzz sequence.

Sample Input 1

15

Sample Output 1

60

The first 15 terms of the FizzBuzz sequence are:

1,2,\mbox{Fizz},4,\mbox{Buzz},\mbox{Fizz},7,8,\mbox{Fizz},\mbox{Buzz},11,\mbox{Fizz},13,14,\mbox{FizzBuzz}

Among them, numbers are 1,2,4,7,8,11,13,14, and the sum of them is 60.

Sample Input 2

1000000

Sample Output 2

266666333332

Watch out for overflow.

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static ABC162B.Input;

namespace ABC162B
{
    static class Input
    {
        // Type Convert
        private static Func<string, T> C<T>()
        {
            Type t = typeof(T);
            if (t == typeof(string)) return _ => (T) (object) _;
            if (t == typeof(int)) return _ => (T) (object) int.Parse(_);
            if (t == typeof(long)) return _ => (T) (object) long.Parse(_);
            if (t == typeof(double)) return _ => (T) (object) double.Parse(_);
            if (t == typeof(char)) return _ => (T) (object) _[0];
            if (t == typeof(string[])) return _ => (T) (object) _.Split(' ');
            if (t == typeof(int[])) return _ => (T) (object) Cast<int>()(_);
            if (t == typeof(long[])) return _ => (T) (object) Cast<long>()(_);
            if (t == typeof(double[])) return _ => (T) (object) Cast<double>()(_);
            if (t == typeof(char[])) return _ => (T) (object) Cast<char>()(_);
            throw new NotSupportedException(t + "is not supported.");
            Func<string, T1[]> Cast<T1>() => _ => _.Split(' ').Select(C<T1>()).ToArray();
        }

        private static T C<T>(string s) => C<T>()(s);

        private static string String() => Console.ReadLine();
        private static string[] Split() => String().Split(' ');
        private static string[] String(long rowNumber) => new bool[rowNumber].Select(_ => String()).ToArray();

        private static (T1, T2) In<T1, T2>(string[] v) => (C<T1>(v[0]), C<T2>(v[1]));
        private static (T1, T2, T3) In<T1, T2, T3>(string[] v) => (C<T1>(v[0]), C<T2>(v[1]), C<T3>(v[2]));

        private static (T1, T2, T3, T4) In<T1, T2, T3, T4>(string[] v) =>
            (C<T1>(v[0]), C<T2>(v[1]), C<T3>(v[2]), C<T4>(v[3]));

        private static (T1, T2, T3, T4, T5) In<T1, T2, T3, T4, T5>(string[] v) =>
            (C<T1>(v[0]), C<T2>(v[1]), C<T3>(v[2]), C<T4>(v[3]), C<T5>(v[4]));

        private static (T1, T2, T3, T4, T5, T6) In<T1, T2, T3, T4, T5, T6>(string[] v) =>
            (C<T1>(v[0]), C<T2>(v[1]), C<T3>(v[2]), C<T4>(v[3]), C<T5>(v[4]), C<T6>(v[5]));

        /* いくつかの変数を受け取る */
        public static void Cin<T>(out T a) => a = C<T>(String());
        public static void Cin<T1, T2>(out T1 a, out T2 b) => (a, b) = In<T1, T2>(Split());

        public static void Cin<T1, T2, T3>(out T1 a, out T2 b, out T3 c) => (a, b, c) = In<T1, T2, T3>(Split());

        public static void Cin<T1, T2, T3, T4>(out T1 a, out T2 b, out T3 c, out T4 d) =>
            (a, b, c, d) = In<T1, T2, T3, T4>(Split());

        public static void Cin<T1, T2, T3, T4, T5>(out T1 a, out T2 b, out T3 c, out T4 d, out T5 e) =>
            (a, b, c, d, e) = In<T1, T2, T3, T4, T5>(Split());

        public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a, out T2 b, out T3 c, out T4 d, out T5 e, out T6 f) =>
            (a, b, c, d, e, f) = In<T1, T2, T3, T4, T5, T6>(Split());

        /* 1行に書かれた配列を受け取る */
        public static void Cin<T>(out T[] a) => a = C<T[]>(String());

        /* n行に書かれたいくつかの配列を受け取る */
        public static void Cin<T>(long n, out T[] l) => l = String(n).Select(C<T>()).ToArray();

        public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2)
        {
            (l1, l2) = (new T1[n], new T2[n]);
            for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i]);
        }

        public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2, out T3[] l3)
        {
            (l1, l2, l3) = (new T1[n], new T2[n], new T3[n]);
            for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i]);
        }

        public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2, out T3[] l3, out T4[] l4)
        {
            (l1, l2, l3, l4) = (new T1[n], new T2[n], new T3[n], new T4[n]);
            for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i], out l4[i]);
        }

        /* T型の行列を受け取る */
        public static void Cin<T>(long h, out T[][] map) => map = String(h).Select(C<T[]>()).ToArray();
    }

    class Program
    {
        public static void Main(string[] args)
        {
            StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            new Solver().Solve();
            Console.Out.Flush();
        }

        public static void Debug()
        {
            new Solver().Solve();
        }
    }

    class Solver
    {
        public void Solve()
        {
            Cin(out int n);
            List<long> ans = new List<long>();
            for (int i = 1; i <= n; i++)
            {
                if (i % 3 != 0 && i % 5 != 0) ans.Add(i);
            }

            Console.WriteLine(ans.Sum());
        }
    }
}