Archive for primeFactors()

Carmichael number, more or less

Posted in Books, Kids, Statistics with tags , , , , , , , on May 6, 2022 by xi'an

A quick-and-dirty R resolution of a riddle from The Riddler, namely to find a Carmichael number of the form abcabc:

library(numbers)
for(i in 1:9)
  for(j in 0:9)
    for(k in 0:9){
      x=i*100100+j*1010+k*101
      if(!isPrime(x)){
        p=primeFactors(x)
        if((prod(apply(outer(p,p,F="=="),1,sum)%%2))&
          (!max((x-1)%%(p-1))))break()}}

resulting into the number 101 101, since its prime factors are

> primeFactors(101101)
[1]   7  11  13 101

and 6, 10, 12, and 100 are divisors of 101100:

> primeFactors(101100) 
[1] 2 2 3 5 5 337

Le Monde puzzle [#1063]

Posted in Books, Kids, R with tags , , , , , , on August 9, 2018 by xi'an

lemondapariA simple (summertime?!) arithmetic Le Monde mathematical puzzle

  1. A “powerful integer” is such that all its prime divisors are at least with multiplicity 2. Are there two powerful integers in a row, i.e. such that both n and n+1 are powerful?
  2.  Are there odd integers n such that n² – 1 is a powerful integer ?

The first question can be solved by brute force.  Here is a R code that leads to the solution:

isperfz <- function(n){ 
  divz=primeFactors(n) 
  facz=unique(divz) 
  ordz=rep(0,length(facz)) 
  for (i in 1:length(facz)) 
    ordz[i]=sum(divz==facz[i]) 
  return(min(ordz)>1)}

lesperf=NULL
for (t in 4:1e5)
if (isperfz(t)) lesperf=c(lesperf,t)
twinz=lesperf[diff(lesperf)==1]

with solutions 8, 288, 675, 9800, 12167.

The second puzzle means rerunning the code only on integers n²-1…

[1] 8
[1] 288
[1] 675
[1] 9800
[1] 235224
[1] 332928
[1] 1825200
[1] 11309768

except that I cannot exceed n²=10⁸. (The Le Monde puzzles will now stop for a month, just like about everything in France!, and then a new challenge will take place. Stay tuned.)

%d bloggers like this: