This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = print . head $ [ x | x <- [1..], allDivided 20 x ] | |
where | |
allDivided 1 _ = True | |
allDivided n x = x `mod` n == 0 && allDivided (n-1) x | |
-- もっと真面目に解ける. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = print . sum $ [ x*y | x<-[1..100], y<-[1..100], x/=y ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int i,j; | |
int result = 0; | |
for(i=1; i<=100; ++i){ | |
for(j=1; j<=100; ++j){ | |
if(i!=j) result += i*j; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = print $ filter isPrime [2..] !! 10000 | |
where | |
isPrime n = null $ filter (\x->n `mod` x==0) [2..floor $ sqrt $ fromIntegral n] | |
-- n が素数かどうかを見るには,[2..sqrt(n)] の数が約数に含まれているかを見れば良い. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <numeric> | |
static const std::string number = "73167176531330624919225119674426574742355349194934" | |
"96983520312774506326239578318016984801869478851843" | |
"85861560789112949495459501737958331952853208805511" | |
"12540698747158523863050715693290963295227443043557" | |
"66896648950445244523161731856403098711121722383113" | |
"62229893423380308135336276614282806444486645238749" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = print [a*b*(1000-a-b) | a<-[1..1000], b<-[a..1000], a^2 + b^2 == (1000-a-b)^2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = print $ sum . filter isPrime $ [2..2000000] | |
where | |
isPrime n = null $ filter (\x->n `mod` x==0) [2..floor $ sqrt $ fromIntegral n] | |
-- 142913828922 ( 11.21s with Core i5, 4G Mem ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
table :: [[Int]] | |
table = [ | |
[8,2,22,97,38,15,0,40,0,75,4,5,7,78,52,12,50,77,91,8], | |
[49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,4,56,62,0], | |
[81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,3,49,13,36,65], | |
[52,70,95,23,4,60,11,42,69,24,68,56,1,32,56,71,37,2,36,91], | |
[22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80], | |
[24,47,32,60,99,3,45,2,44,75,33,53,78,36,84,20,35,17,12,50], | |
[32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70], | |
[67,26,20,68,2,62,12,20,95,63,94,39,63,8,40,91,66,49,94,21], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
factors :: Int -> [Int] | |
factors n = filter (\x -> n `mod` x == 0) [1..n] | |
triNums :: [Int] | |
triNums = [ sum [1..x] | x<-[1..] ] | |
main = print $ find (\x -> length(factors x) > 500) triNums |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (maximumBy) | |
import Data.Function (on) | |
collatzLength :: Int -> Int | |
collatzLength 1 = 1 | |
collatzLength n | |
| even n = 1 + collatzLength(n `div` 2) | |
| odd n = 1 + collatzLength(3*n + 1) | |
main = print $ maximumBy (compare `on` collatzLength) [1..1000000] |