WeixiangYan/CodeTransOcean huggingface dataset:
Task: Averages_Pythagorean means

C: #include <stdio.h>
#include <stdlib.h> 
#include <math.h> 

int main(int argc, char* argv[])
{
  int i, count=0;
  double f, sum=0.0, prod=1.0, resum=0.0;

  for (i=1; i<argc; ++i) {
    f = atof(argv[i]);
    count++;
    sum += f;
    prod *= f;
    resum += (1.0/f);
  }
  
  printf("Arithmetic mean = %f\n",sum/count);
  printf("Geometric mean = %f\n",pow(prod,(1.0/count)));
  printf("Harmonic mean = %f\n",count/resum);

  return 0;
}
Task: Averages_Pythagorean means



C#: using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace PythMean
{
    static class Program
    {
        static void Main(string[] args) {
            var nums = from n in Enumerable.Range(1, 10) select (double)n;

            var a = nums.Average();
            var g = nums.Gmean();
            var h = nums.Hmean();

            Console.WriteLine("Arithmetic mean {0}", a);
            Console.WriteLine("Geometric mean  {0}", g);
            Console.WriteLine("Harmonic mean   {0}", h);

            Debug.Assert(a >= g && g >= h);
        }

        
        static double Gmean(this IEnumerable<double> n) {
            return Math.Pow(n.Aggregate((s, i) => s * i), 1.0 / n.Count());
        }

        
        static double Hmean(this IEnumerable<double> n) {
            return n.Count() / n.Sum(i => 1.0 / i);
        }
    }
}
Task: Averages_Pythagorean means


C++: #include <vector>
#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>

double toInverse ( int i ) {
   return  1.0 / i  ;
}

int main( ) {
   std::vector<int> numbers ;
   for ( int i = 1 ; i < 11 ; i++ ) 
      numbers.push_back( i ) ;
   double arithmetic_mean = std::accumulate( numbers.begin( ) , numbers.end( ) , 0 ) / 10.0 ;
   double geometric_mean =
      pow( std::accumulate( numbers.begin( ) , numbers.end( ) , 1 , std::multiplies<int>( ) ), 0.1 ) ;
   std::vector<double> inverses ;
   inverses.resize( numbers.size( ) ) ;
   std::transform( numbers.begin( ) , numbers.end( ) , inverses.begin( ) , toInverse ) ;  
   double harmonic_mean = 10 / std::accumulate( inverses.begin( ) , inverses.end( ) , 0.0 ); 
   std::cout << "The arithmetic mean is " << arithmetic_mean << " , the geometric mean " 
      << geometric_mean << " and the harmonic mean " << harmonic_mean << " !\n" ;
   return 0 ;
}
Task: Averages_Pythagorean means





Java: import java.util.Arrays;
import java.util.List;

public class PythagoreanMeans {
    public static double arithmeticMean(List<Double> numbers) {
        if (numbers.isEmpty()) return Double.NaN;
        double mean = 0.0;
        for (Double number : numbers) {
            mean += number;
        }
        return mean / numbers.size();
    }

    public static double geometricMean(List<Double> numbers) {
        if (numbers.isEmpty()) return Double.NaN;
        double mean = 1.0;
        for (Double number : numbers) {
            mean *= number;
        }
        return Math.pow(mean, 1.0 / numbers.size());
    }

    public static double harmonicMean(List<Double> numbers) {
        if (numbers.isEmpty() || numbers.contains(0.0)) return Double.NaN;
        double mean = 0.0;
        for (Double number : numbers) {
            mean += (1.0 / number);
        }
        return numbers.size() / mean;
    }

    public static void main(String[] args) {
        Double[] array = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
        List<Double> list = Arrays.asList(array);
        double arithmetic = arithmeticMean(list);
        double geometric = geometricMean(list);
        double harmonic = harmonicMean(list);
        System.out.format("A = %f  G = %f  H = %f%n", arithmetic, geometric, harmonic);
        System.out.format("A >= G is %b, G >= H is %b%n", (arithmetic >= geometric), (geometric >= harmonic));
    }
}
Task: Averages_Pythagorean means







Python: from operator import mul
from functools import reduce


def amean(num):
    return sum(num) / len(num)


def gmean(num):
    return reduce(mul, num, 1)**(1 / len(num))


def hmean(num):
    return len(num) / sum(1 / n for n in num)


numbers = range(1, 11)  
a, g, h = amean(numbers), gmean(numbers), hmean(numbers)
print(a, g, h)
assert a >= g >= h
Task: Averages_Pythagorean means








VB: Private Function arithmetic_mean(s() As Variant) As Double
    arithmetic_mean = WorksheetFunction.Average(s)
End Function
Private Function geometric_mean(s() As Variant) As Double
    geometric_mean = WorksheetFunction.GeoMean(s)
End Function
Private Function harmonic_mean(s() As Variant) As Double
    harmonic_mean = WorksheetFunction.HarMean(s)
End Function
Public Sub pythagorean_means()
    Dim s() As Variant
    s = [{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]
    Debug.Print "A ="; arithmetic_mean(s)
    Debug.Print "G ="; geometric_mean(s)
    Debug.Print "H ="; harmonic_mean(s)
End Sub
Task: Averages_Pythagorean means




Go: package main

import (
    "fmt"
    "math"
)

func main() {
    sum, sumr, prod := 0., 0., 1.
    for n := 1.; n <= 10; n++ {
        sum += n
        sumr += 1 / n
        prod *= n
    }
    a, g, h := sum/10, math.Pow(prod, .1), 10/sumr
    fmt.Println("A:", a, "G:", g, "H:", h)
    fmt.Println("A >= G >= H:", a >= g && g >= h)
}
Task: Averages_Pythagorean means



C#: using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace PythMean
{
    static class Program
    {
        static void Main(string[] args) {
            var nums = from n in Enumerable.Range(1, 10) select (double)n;

            var a = nums.Average();
            var g = nums.Gmean();
            var h = nums.Hmean();

            Console.WriteLine("Arithmetic mean {0}", a);
            Console.WriteLine("Geometric mean  {0}", g);
            Console.WriteLine("Harmonic mean   {0}", h);

            Debug.Assert(a >= g && g >= h);
        }

        
        static double Gmean(this IEnumerable<double> n) {
            return Math.Pow(n.Aggregate((s, i) => s * i), 1.0 / n.Count());
        }

        
        static double Hmean(this IEnumerable<double> n) {
            return n.Count() / n.Sum(i => 1.0 / i);
        }
    }
}








Fortran: program Mean

  real :: a(10) = (/ (i, i=1,10) /)
  real :: amean, gmean, hmean

  amean = sum(a) / size(a)
  gmean = product(a)**(1.0/size(a))
  hmean = size(a) / sum(1.0/a)

  if ((amean < gmean) .or. (gmean < hmean)) then
    print*, "Error
  else
    print*, amean, gmean, hmean
  end if

end program Mean
Task: Averages_Pythagorean means


C++: #include <vector>
#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>

double toInverse ( int i ) {
   return  1.0 / i  ;
}

int main( ) {
   std::vector<int> numbers ;
   for ( int i = 1 ; i < 11 ; i++ ) 
      numbers.push_back( i ) ;
   double arithmetic_mean = std::accumulate( numbers.begin( ) , numbers.end( ) , 0 ) / 10.0 ;
   double geometric_mean =
      pow( std::accumulate( numbers.begin( ) , numbers.end( ) , 1 , std::multiplies<int>( ) ), 0.1 ) ;
   std::vector<double> inverses ;
   inverses.resize( numbers.size( ) ) ;
   std::transform( numbers.begin( ) , numbers.end( ) , inverses.begin( ) , toInverse ) ;  
   double harmonic_mean = 10 / std::accumulate( inverses.begin( ) , inverses.end( ) , 0.0 ); 
   std::cout << "The arithmetic mean is " << arithmetic_mean << " , the geometric mean " 
      << geometric_mean << " and the harmonic mean " << harmonic_mean << " !\n" ;
   return 0 ;
}









Fortran: program Mean

  real :: a(10) = (/ (i, i=1,10) /)
  real :: amean, gmean, hmean

  amean = sum(a) / size(a)
  gmean = product(a)**(1.0/size(a))
  hmean = size(a) / sum(1.0/a)

  if ((amean < gmean) .or. (gmean < hmean)) then
    print*, "Error
  else
    print*, amean, gmean, hmean
  end if

end program Mean
Task: Averages_Pythagorean means

C: #include <stdio.h>
#include <stdlib.h> 
#include <math.h> 

int main(int argc, char* argv[])
{
  int i, count=0;
  double f, sum=0.0, prod=1.0, resum=0.0;

  for (i=1; i<argc; ++i) {
    f = atof(argv[i]);
    count++;
    sum += f;
    prod *= f;
    resum += (1.0/f);
  }
  
  printf("Arithmetic mean = %f\n",sum/count);
  printf("Geometric mean = %f\n",pow(prod,(1.0/count)));
  printf("Harmonic mean = %f\n",count/resum);

  return 0;
}










Fortran: program Mean

  real :: a(10) = (/ (i, i=1,10) /)
  real :: amean, gmean, hmean

  amean = sum(a) / size(a)
  gmean = product(a)**(1.0/size(a))
  hmean = size(a) / sum(1.0/a)

  if ((amean < gmean) .or. (gmean < hmean)) then
    print*, "Error
  else
    print*, amean, gmean, hmean
  end if

end program Mean
Task: Averages_Pythagorean means





Java: import java.util.Arrays;
import java.util.List;

public class PythagoreanMeans {
    public static double arithmeticMean(List<Double> numbers) {
        if (numbers.isEmpty()) return Double.NaN;
        double mean = 0.0;
        for (Double number : numbers) {
            mean += number;
        }
        return mean / numbers.size();
    }

    public static double geometricMean(List<Double> numbers) {
        if (numbers.isEmpty()) return Double.NaN;
        double mean = 1.0;
        for (Double number : numbers) {
            mean *= number;
        }
        return Math.pow(mean, 1.0 / numbers.size());
    }

    public static double harmonicMean(List<Double> numbers) {
        if (numbers.isEmpty() || numbers.contains(0.0)) return Double.NaN;
        double mean = 0.0;
        for (Double number : numbers) {
            mean += (1.0 / number);
        }
        return numbers.size() / mean;
    }

    public static void main(String[] args) {
        Double[] array = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
        List<Double> list = Arrays.asList(array);
        double arithmetic = arithmeticMean(list);
        double geometric = geometricMean(list);
        double harmonic = harmonicMean(list);
        System.out.format("A = %f  G = %f  H = %f%n", arithmetic, geometric, harmonic);
        System.out.format("A >= G is %b, G >= H is %b%n", (arithmetic >= geometric), (geometric >= harmonic));
    }
}






Fortran: program Mean

  real :: a(10) = (/ (i, i=1,10) /)
  real :: amean, gmean, hmean

  amean = sum(a) / size(a)
  gmean = product(a)**(1.0/size(a))
  hmean = size(a) / sum(1.0/a)

  if ((amean < gmean) .or. (gmean < hmean)) then
    print*, "Error
  else
    print*, amean, gmean, hmean
  end if

end program Mean
Task: Averages_Pythagorean means







Python: from operator import mul
from functools import reduce


def amean(num):
    return sum(num) / len(num)


def gmean(num):
    return reduce(mul, num, 1)**(1 / len(num))


def hmean(num):
    return len(num) / sum(1 / n for n in num)


numbers = range(1, 11)  
a, g, h = amean(numbers), gmean(numbers), hmean(numbers)
print(a, g, h)
assert a >= g >= h




Fortran: program Mean

  real :: a(10) = (/ (i, i=1,10) /)
  real :: amean, gmean, hmean

  amean = sum(a) / size(a)
  gmean = product(a)**(1.0/size(a))
  hmean = size(a) / sum(1.0/a)

  if ((amean < gmean) .or. (gmean < hmean)) then
    print*, "Error
  else
    print*, amean, gmean, hmean
  end if

end program Mean
Task: Averages_Pythagorean means








VB: Private Function arithmetic_mean(s() As Variant) As Double
    arithmetic_mean = WorksheetFunction.Average(s)
End Function
Private Function geometric_mean(s() As Variant) As Double
    geometric_mean = WorksheetFunction.GeoMean(s)
End Function
Private Function harmonic_mean(s() As Variant) As Double
    harmonic_mean = WorksheetFunction.HarMean(s)
End Function
Public Sub pythagorean_means()
    Dim s() As Variant
    s = [{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]
    Debug.Print "A ="; arithmetic_mean(s)
    Debug.Print "G ="; geometric_mean(s)
    Debug.Print "H ="; harmonic_mean(s)
End Sub



Fortran: program Mean

  real :: a(10) = (/ (i, i=1,10) /)
  real :: amean, gmean, hmean

  amean = sum(a) / size(a)
  gmean = product(a)**(1.0/size(a))
  hmean = size(a) / sum(1.0/a)

  if ((amean < gmean) .or. (gmean < hmean)) then
    print*, "Error
  else
    print*, amean, gmean, hmean
  end if

end program Mean
Task: Averages_Pythagorean means






PHP: <?php


function ArithmeticMean(array $values)
{
    return array_sum($values) / count($values);
}

function GeometricMean(array $values)
{
    return array_product($values) ** (1 / count($values));
}

function HarmonicMean(array $values)
{
    $sum = 0;

    foreach ($values as $value) {
        $sum += 1 / $value;
    }

    return count($values) / $sum;
}

$values = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

echo "Arithmetic: " . ArithmeticMean($values) . "\n";
echo "Geometric: " . GeometricMean($values) . "\n";
echo "Harmonic: " . HarmonicMean($values) . "\n";





Fortran: program Mean

  real :: a(10) = (/ (i, i=1,10) /)
  real :: amean, gmean, hmean

  amean = sum(a) / size(a)
  gmean = product(a)**(1.0/size(a))
  hmean = size(a) / sum(1.0/a)

  if ((amean < gmean) .or. (gmean < hmean)) then
    print*, "Error
  else
    print*, amean, gmean, hmean
  end if

end program Mean
Task: Averages_Pythagorean means






PHP: <?php


function ArithmeticMean(array $values)
{
    return array_sum($values) / count($values);
}

function GeometricMean(array $values)
{
    return array_product($values) ** (1 / count($values));
}

function HarmonicMean(array $values)
{
    $sum = 0;

    foreach ($values as $value) {
        $sum += 1 / $value;
    }

    return count($values) / $sum;
}

$values = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

echo "Arithmetic: " . ArithmeticMean($values) . "\n";
echo "Geometric: " . GeometricMean($values) . "\n";
echo "Harmonic: " . HarmonicMean($values) . "\n";
Task: Averages_Pythagorean means






PHP: <?php


function ArithmeticMean(array $values)
{
    return array_sum($values) / count($values);
}

function GeometricMean(array $values)
{
    return array_product($values) ** (1 / count($values));
}

function HarmonicMean(array $values)
{
    $sum = 0;

    foreach ($values as $value) {
        $sum += 1 / $value;
    }

    return count($values) / $sum;
}

$values = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

echo "Arithmetic: " . ArithmeticMean($values) . "\n";
echo "Geometric: " . GeometricMean($values) . "\n";
echo "Harmonic: " . HarmonicMean($values) . "\n";






Ada: package Pythagorean_Means is
   type Set is array (Positive range <>) of Float;
   function Arithmetic_Mean (Data : Set) return Float;
   function Geometric_Mean  (Data : Set) return Float;
   function Harmonic_Mean   (Data : Set) return Float;
end Pythagorean_Means;
Task: Wieferich primes



C#: using System;
using System.Collections.Generic;
using System.Linq;

namespace WieferichPrimes {
    class Program {
        static long ModPow(long @base, long exp, long mod) {
            if (mod == 1) {
                return 0;
            }

            long result = 1;
            @base %= mod;
            for (; exp > 0; exp >>= 1) {
                if ((exp & 1) == 1) {
                    result = (result * @base) % mod;
                }
                @base = (@base * @base) % mod;
            }
            return result;
        }

        static bool[] PrimeSieve(int limit) {
            bool[] sieve = Enumerable.Repeat(true, limit).ToArray();

            if (limit > 0) {
                sieve[0] = false;
            }
            if (limit > 1) {
                sieve[1] = false;
            }

            for (int i = 4; i < limit; i += 2) {
                sieve[i] = false;
            }

            for (int p = 3; ; p += 2) {
                int q = p * p;
                if (q >= limit) {
                    break;
                }
                if (sieve[p]) {
                    int inc = 2 * p;
                    for (; q < limit; q += inc) {
                        sieve[q] = false;
                    }
                }
            }

            return sieve;
        }

        static List<int> WiefreichPrimes(int limit) {
            bool[] sieve = PrimeSieve(limit);
            List<int> result = new List<int>();
            for (int p = 2; p < limit; p++) {
                if (sieve[p] && ModPow(2, p - 1, p * p) == 1) {
                    result.Add(p);
                }
            }
            return result;
        }

        static void Main() {
            const int limit = 5000;
            Console.WriteLine("Wieferich primes less that {0}:", limit);
            foreach (int p in WiefreichPrimes(limit)) {
                Console.WriteLine(p);
            }
        }
    }
}









Ada: with Ada.Text_IO;

procedure Wieferich_Primes is

   function Is_Prime (V : Positive) return Boolean is
      D : Positive := 5;
   begin
      if V < 2       then return False; end if;
      if V mod 2 = 0 then return V = 2; end if;
      if V mod 3 = 0 then return V = 3; end if;
      while D * D <= V loop
         if V mod D = 0 then
            return False;
         end if;
         D := D + 2;
      end loop;
      return True;
   end Is_Prime;

   function Is_Wieferich (N : Positive) return Boolean is
      Q : Natural := 1;
   begin
      if not Is_Prime (N) then
         return False;
      end if;
      for P in 2 .. N loop
         Q := (2 * Q) mod N**2;
      end loop;
      return Q = 1;
   end Is_Wieferich;

begin

   Ada.Text_IO.Put_Line ("Wieferich primes below 5000:");
   for N in 1 .. 4999 loop
      if Is_Wieferich (N) then
         Ada.Text_IO.Put_Line (N'Image);
      end if;
   end loop;

end Wieferich_Primes;
Task: Wieferich primes

C: #include <stdbool.h>
#include <stdio.h>
#include <stdint.h>

#define LIMIT 5000
static bool PRIMES[LIMIT];

static void prime_sieve() {
    uint64_t p;
    int i;

    PRIMES[0] = false;
    PRIMES[1] = false;
    for (i = 2; i < LIMIT; i++) {
        PRIMES[i] = true;
    }

    for (i = 4; i < LIMIT; i += 2) {
        PRIMES[i] = false;
    }

    for (p = 3;; p += 2) {
        uint64_t q = p * p;
        if (q >= LIMIT) {
            break;
        }
        if (PRIMES[p]) {
            uint64_t inc = 2 * p;
            for (; q < LIMIT; q += inc) {
                PRIMES[q] = false;
            }
        }
    }
}

uint64_t modpow(uint64_t base, uint64_t exp, uint64_t mod) {
    uint64_t result = 1;

    if (mod == 1) {
        return 0;
    }

    base %= mod;
    for (; exp > 0; exp >>= 1) {
        if ((exp & 1) == 1) {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
    }
    return result;
}

void wieferich_primes() {
    uint64_t p;

    for (p = 2; p < LIMIT; ++p) {
        if (PRIMES[p] && modpow(2, p - 1, p * p) == 1) {
            printf("%lld\n", p);
        }
    }
}

int main() {
    prime_sieve();

    printf("Wieferich primes less than %d:\n", LIMIT);
    wieferich_primes();

    return 0;
}











Ada: with Ada.Text_IO;

procedure Wieferich_Primes is

   function Is_Prime (V : Positive) return Boolean is
      D : Positive := 5;
   begin
      if V < 2       then return False; end if;
      if V mod 2 = 0 then return V = 2; end if;
      if V mod 3 = 0 then return V = 3; end if;
      while D * D <= V loop
         if V mod D = 0 then
            return False;
         end if;
         D := D + 2;
      end loop;
      return True;
   end Is_Prime;

   function Is_Wieferich (N : Positive) return Boolean is
      Q : Natural := 1;
   begin
      if not Is_Prime (N) then
         return False;
      end if;
      for P in 2 .. N loop
         Q := (2 * Q) mod N**2;
      end loop;
      return Q = 1;
   end Is_Wieferich;

begin

   Ada.Text_IO.Put_Line ("Wieferich primes below 5000:");
   for N in 1 .. 4999 loop
      if Is_Wieferich (N) then
         Ada.Text_IO.Put_Line (N'Image);
      end if;
   end loop;

end Wieferich_Primes;
Task: Wieferich primes


C++: #include <cstdint>
#include <iostream>
#include <vector>

std::vector<bool> prime_sieve(uint64_t limit) {
    std::vector<bool> sieve(limit, true);
    if (limit > 0)
        sieve[0] = false;
    if (limit > 1)
        sieve[1] = false;
    for (uint64_t i = 4; i < limit; i += 2)
        sieve[i] = false;
    for (uint64_t p = 3; ; p += 2) {
        uint64_t q = p * p;
        if (q >= limit)
            break;
        if (sieve[p]) {
            uint64_t inc = 2 * p;
            for (; q < limit; q += inc)
                sieve[q] = false;
        }
    }
    return sieve;
}

uint64_t modpow(uint64_t base, uint64_t exp, uint64_t mod) {
    if (mod == 1)
        return 0;
    uint64_t result = 1;
    base %= mod;
    for (; exp > 0; exp >>= 1) {
        if ((exp & 1) == 1)
            result = (result * base) % mod;
        base = (base * base) % mod;
    }
    return result;
}

std::vector<uint64_t> wieferich_primes(uint64_t limit) {
    std::vector<uint64_t> result;
    std::vector<bool> sieve(prime_sieve(limit));
    for (uint64_t p = 2; p < limit; ++p)
        if (sieve[p] && modpow(2, p - 1, p * p) == 1)
            result.push_back(p);
    return result;
}

int main() {
    const uint64_t limit = 5000;
    std::cout << "Wieferich primes less than " << limit << ":\n";
    for (uint64_t p : wieferich_primes(limit))
        std::cout << p << '\n';
}










Ada: with Ada.Text_IO;

procedure Wieferich_Primes is

   function Is_Prime (V : Positive) return Boolean is
      D : Positive := 5;
   begin
      if V < 2       then return False; end if;
      if V mod 2 = 0 then return V = 2; end if;
      if V mod 3 = 0 then return V = 3; end if;
      while D * D <= V loop
         if V mod D = 0 then
            return False;
         end if;
         D := D + 2;
      end loop;
      return True;
   end Is_Prime;

   function Is_Wieferich (N : Positive) return Boolean is
      Q : Natural := 1;
   begin
      if not Is_Prime (N) then
         return False;
      end if;
      for P in 2 .. N loop
         Q := (2 * Q) mod N**2;
      end loop;
      return Q = 1;
   end Is_Wieferich;

begin

   Ada.Text_IO.Put_Line ("Wieferich primes below 5000:");
   for N in 1 .. 4999 loop
      if Is_Wieferich (N) then
         Ada.Text_IO.Put_Line (N'Image);
      end if;
   end loop;

end Wieferich_Primes;
Task: Wieferich primes




Go: package main

import (
    "fmt"
    "math/big"
    "rcu"
)

func main() {
    primes := rcu.Primes(5000)
    zero := new(big.Int)
    one := big.NewInt(1)
    num := new(big.Int)
    fmt.Println("Wieferich primes < 5,000:")
    for _, p := range primes {
        num.Set(one)
        num.Lsh(num, uint(p-1))
        num.Sub(num, one)
        den := big.NewInt(int64(p * p))
        if num.Rem(num, den).Cmp(zero) == 0 {
            fmt.Println(rcu.Commatize(p))
        }
    }
}








Ada: with Ada.Text_IO;

procedure Wieferich_Primes is

   function Is_Prime (V : Positive) return Boolean is
      D : Positive := 5;
   begin
      if V < 2       then return False; end if;
      if V mod 2 = 0 then return V = 2; end if;
      if V mod 3 = 0 then return V = 3; end if;
      while D * D <= V loop
         if V mod D = 0 then
            return False;
         end if;
         D := D + 2;
      end loop;
      return True;
   end Is_Prime;

   function Is_Wieferich (N : Positive) return Boolean is
      Q : Natural := 1;
   begin
      if not Is_Prime (N) then
         return False;
      end if;
      for P in 2 .. N loop
         Q := (2 * Q) mod N**2;
      end loop;
      return Q = 1;
   end Is_Wieferich;

begin

   Ada.Text_IO.Put_Line ("Wieferich primes below 5000:");
   for N in 1 .. 4999 loop
      if Is_Wieferich (N) then
         Ada.Text_IO.Put_Line (N'Image);
      end if;
   end loop;

end Wieferich_Primes;