Sha256: 5666089c65227bea9d971a5ab2ad0da837e628a6cfa22d9647bb5dee9278ea6e
Contents?: true
Size: 496 Bytes
Versions: 15
Compression:
Stored size: 496 Bytes
Contents
# coding: utf-8 class Integer def untouchable? # * The first untouchable integer is 2 # * Perfect numbers are never untouchable because they can be expressed # as the sum of their own proper divisors # * If p is prime, the sum of the proper divisors of p**2 is p + 1; # therefore, no untouchable number is one more than a prime. return false if self < 2 or perfect? or (self - 1).prime? (1..((self - 1)**2)).none? do |m| m.σ - m == self end end end
Version data entries
15 entries across 15 versions & 1 rubygems