Puzzle/ProjectEuler
[Project Euler] Problem 1: Multiples of 3 and 5
More Code
2019. 4. 19. 04:21
참고 :
https://www.nayuki.io/page/project-euler-solutions
https://projecteuler.net/problem=1
# Python 3
total: int = 0
for i in range(1, 1000):
if i % 3 == 0 or i % 5 == 0:
total += i
print("total =", total)
# Python 3
print(sum([i for i in range(1, 1000) if i % 3 == 0 or i % 5 == 0]))
// C/C++
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tchar.h>
int _tmain(INT32 argc, LPTSTR argv[]) {
INT32 total = 0;
for (INT32 i = 1; i < 1000; i++) {
if (i % 3 == 0 || i % 5 == 0) {
total += i;
}
}
_tprintf(_T("total = %d"), total);
return EXIT_SUCCESS;
}
// C#
using System;
namespace Sharp1
{
class Program
{
static void Main(string[] args)
{
int total = 0;
for (int i = 1; i < 1000; i++)
{
if (i % 3 == 0 || i % 5 == 0)
{
total += i;
}
}
Console.Write("total = {0}", total);
}
}
}
// Java
package coffee;
public class Program {
public static void main(String[] args) {
int total = 0;
for (int i = 1; i < 1000; i++) {
if (i % 3 == 0 || i % 5 == 0) {
total += i;
}
}
System.out.printf("total = %d ", total);
}
}