Divisibility Tests

Author

Eric W. Weisstein
January 24, 2009

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Algebra/DivisibilityTests.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/DivisibilityTests.html.

©2009 Wolfram Research, Inc. except for portions noted otherwise

1

Mod[Range[10^3],1]//Union

2

Position[Mod[IntegerDigits[#,10,1][[1]],2]&/@Range[20],0]//Flatten

Position[Mod[#,2]&/@Range[20],0]//Flatten

3

Position[Mod[Plus@@IntegerDigits[#],3]&/@Range[20],0]//Flatten

Position[Mod[#,3]&/@Range[20],0]//Flatten

4

Position[Mod[FromDigits[IntegerDigits[#,10,2]],4]&/@Range[50],0]//Flatten

Position[Mod[{2,1}.IntegerDigits[#,10,2],4]&/@Range[50],0]//Flatten

Position[Mod[#,4]&/@Range[50],0]//Flatten

5

Position[Mod[IntegerDigits[#,10,1][[1]],5]&/@Range[50],0]//Flatten

Position[Mod[#,5]&/@Range[50],0]//Flatten

6

7

DivisibleBy[7,n_,meth_]:=(FixedPoint[reduce7[#,meth]&,n]==7)

b

reduce7[n_,left]:=Module[{d=IntegerDigits[n]},
Nest[Prepend[Drop[#,2],3First[#]+#[[2]]]&,d,Length[d]-1][[1]]
]

reduce7[7211,right]

c

reduce7[n_,right]:=Module[{d=IntegerDigits[n]},
Nest[Append[Drop[#,-2],5Last[#]+#[[-2]]]&,d,Length[d]-1][[1]]
]

reduce7[7211,left]

d

DivisibleBy[7,n_]:=Module[{d},
Mod[NestWhile[FromDigits[Most[d=IntegerDigits[#]]]-2Last[d]&,n,Positive],7]==0
]

DivisibleBy[7,#]&/@Range[14]

DivisibleBy[7,65541]

NestWhileList[FromDigits[Most[d=IntegerDigits[#]]]-2Last[d]&,65534,Positive]

NestWhileList[FromDigits[Most[d=IntegerDigits[#]]]-2Last[d]&,65541,Positive]

e

DivisibleBy7e[n_]:=Total[IntegerDigits[n,8]]

Select[Range[1000],Mod[#,7]==0&]==Select[Range[1000],Mod[Total[IntegerDigits[#,8]],7]==0&]

Words with i's

Phrases and OED

{#[[1,1]]->#[[All,2]]}&/@SplitBy[Sort[{Count[Characters[#],"i"],#}&/@{"indivisibilities","indistinguishabilities","honorificabilitudinitatibus","floccinaucinihilipilification","supercalifragilisticexpialidocious","infinite divisibility","illinois fighting illini"}],First]//Column

DictionaryLookup

Length[words=DictionaryLookup[]]

is={Count[Characters[#],"i"],#}&/@words;

{#[[1,1]]->#[[All,2]]}&/@SplitBy[Sort[Select[is,First[#]>4&]],First]//Column

WordData

Length[phrases=WordData[]]//Timing

is={Count[Characters[#],"i"],#}&/@phrases;//Timing

{#[[1,1]]->#[[All,2]]}&/@SplitBy[Sort[Select[is,First[#]>5&]],First]//Column

{#[[1,1]]->#[[All,2]]}&/@SplitBy[Sort[Select[is,FreeQ[Characters[Last[#]]," "]&&First[#]>5&]],First]//Column