WeixiangYan/CodeTransOcean huggingface dataset:
Task: List comprehensions





Java: 
import java.util.Arrays;
import java.util.List;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toList;
import static java.util.stream.IntStream.range;
public interface PythagComp{
    static void main(String... args){
        System.out.println(run(20));
    }

    static List<List<Integer>> run(int n){
        return
            
            
            range(1, n).mapToObj(
                x -> range(x, n).mapToObj(
                    y -> range(y, n).mapToObj(
                        z -> new Integer[]{x, y, z}
                    )
                )
            )
                .flatMap(identity())
                .flatMap(identity())
                
                .filter(a -> a[0]*a[0] + a[1]*a[1] == a[2]*a[2])
                
                .map(Arrays::asList)
                
                .collect(toList())
        ;
    }
}







Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Doubly_Linked_Lists;

procedure Pythagore_Set is

   type Triangles is array (1 .. 3) of Positive;

   package Triangle_Lists is new Ada.Containers.Doubly_Linked_Lists (
      Triangles);
   use Triangle_Lists;

   function Find_List (Upper_Bound : Positive) return List is
      L : List := Empty_List;
   begin
      for A in 1 .. Upper_Bound loop
         for B in A + 1 .. Upper_Bound loop
            for C in B + 1 .. Upper_Bound loop
               if ((A * A + B * B) = C * C) then
                  Append (L, (A, B, C));
               end if;
            end loop;
         end loop;
      end loop;
      return L;
   end Find_List;

   Triangle_List : List;
   C             : Cursor;
   T             : Triangles;

begin
   Triangle_List := Find_List (Upper_Bound => 20);

   C := First (Triangle_List);
   while Has_Element (C) loop
      T := Element (C);
      Put
        ("(" &
         Integer'Image (T (1)) &
         Integer'Image (T (2)) &
         Integer'Image (T (3)) &
         ") ");
      Next (C);
   end loop;
end Pythagore_Set;
Task: List comprehensions







Python: [(x,y,z) for x in xrange(1,n+1) for y in xrange(x,n+1) for z in xrange(y,n+1) if x**2 + y**2 == z**2]





Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Doubly_Linked_Lists;

procedure Pythagore_Set is

   type Triangles is array (1 .. 3) of Positive;

   package Triangle_Lists is new Ada.Containers.Doubly_Linked_Lists (
      Triangles);
   use Triangle_Lists;

   function Find_List (Upper_Bound : Positive) return List is
      L : List := Empty_List;
   begin
      for A in 1 .. Upper_Bound loop
         for B in A + 1 .. Upper_Bound loop
            for C in B + 1 .. Upper_Bound loop
               if ((A * A + B * B) = C * C) then
                  Append (L, (A, B, C));
               end if;
            end loop;
         end loop;
      end loop;
      return L;
   end Find_List;

   Triangle_List : List;
   C             : Cursor;
   T             : Triangles;

begin
   Triangle_List := Find_List (Upper_Bound => 20);

   C := First (Triangle_List);
   while Has_Element (C) loop
      T := Element (C);
      Put
        ("(" &
         Integer'Image (T (1)) &
         Integer'Image (T (2)) &
         Integer'Image (T (3)) &
         ") ");
      Next (C);
   end loop;
end Pythagore_Set;
Task: List comprehensions








VB: Module ListComp
    Sub Main()
        Dim ts = From a In Enumerable.Range(1, 20) _
                 From b In Enumerable.Range(a, 21 - a) _
                 From c In Enumerable.Range(b, 21 - b) _
                 Where a * a + b * b = c * c _
                 Select New With { a, b, c }
        
        For Each t In ts
            System.Console.WriteLine("{0}, {1}, {2}", t.a, t.b, t.c)
        Next
    End Sub
End Module




Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Doubly_Linked_Lists;

procedure Pythagore_Set is

   type Triangles is array (1 .. 3) of Positive;

   package Triangle_Lists is new Ada.Containers.Doubly_Linked_Lists (
      Triangles);
   use Triangle_Lists;

   function Find_List (Upper_Bound : Positive) return List is
      L : List := Empty_List;
   begin
      for A in 1 .. Upper_Bound loop
         for B in A + 1 .. Upper_Bound loop
            for C in B + 1 .. Upper_Bound loop
               if ((A * A + B * B) = C * C) then
                  Append (L, (A, B, C));
               end if;
            end loop;
         end loop;
      end loop;
      return L;
   end Find_List;

   Triangle_List : List;
   C             : Cursor;
   T             : Triangles;

begin
   Triangle_List := Find_List (Upper_Bound => 20);

   C := First (Triangle_List);
   while Has_Element (C) loop
      T := Element (C);
      Put
        ("(" &
         Integer'Image (T (1)) &
         Integer'Image (T (2)) &
         Integer'Image (T (3)) &
         ") ");
      Next (C);
   end loop;
end Pythagore_Set;
Task: List comprehensions

C: for (int i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); }
Task: List comprehensions



C#: using System.Linq;

static class Program
{
  static void Main()
  {
    var ts =
      from a in Enumerable.Range(1, 20)
      from b in Enumerable.Range(a, 21 - a)
      from c in Enumerable.Range(b, 21 - b)
      where a * a + b * b == c * c
      select new { a, b, c };

      foreach (var t in ts)
        System.Console.WriteLine("{0}, {1}, {2}", t.a, t.b, t.c);
  }
}
Task: List comprehensions


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

void list_comprehension( std::vector<int> & , int ) ;

int main( ) {
   std::vector<int> triangles ;
   list_comprehension( triangles , 20 ) ;
   std::copy( triangles.begin( ) , triangles.end( ) ,
	 std::ostream_iterator<int>( std::cout , " " ) ) ;
   std::cout << std::endl ;
   return 0 ;
}

void list_comprehension( std::vector<int> & numbers , int upper_border ) {
   for ( int a = 1 ; a < upper_border ; a++ ) {
      for ( int b = a + 1 ; b < upper_border ; b++ ) {
	 double c = pow( a * a + b * b , 0.5 ) ; 
	 if ( ( c * c ) < pow( upper_border , 2 ) + 1 ) {
	    if ( c == floor( c ) ) {
	       numbers.push_back( a ) ;
	       numbers.push_back( b ) ;	      
	       numbers.push_back( static_cast<int>( c ) ) ;
	    }
	 }
      }
   }
}
Task: List comprehensions





Java: 
import java.util.Arrays;
import java.util.List;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toList;
import static java.util.stream.IntStream.range;
public interface PythagComp{
    static void main(String... args){
        System.out.println(run(20));
    }

    static List<List<Integer>> run(int n){
        return
            
            
            range(1, n).mapToObj(
                x -> range(x, n).mapToObj(
                    y -> range(y, n).mapToObj(
                        z -> new Integer[]{x, y, z}
                    )
                )
            )
                .flatMap(identity())
                .flatMap(identity())
                
                .filter(a -> a[0]*a[0] + a[1]*a[1] == a[2]*a[2])
                
                .map(Arrays::asList)
                
                .collect(toList())
        ;
    }
}
Task: List comprehensions







Python: [(x,y,z) for x in xrange(1,n+1) for y in xrange(x,n+1) for z in xrange(y,n+1) if x**2 + y**2 == z**2]
Task: List comprehensions








VB: Module ListComp
    Sub Main()
        Dim ts = From a In Enumerable.Range(1, 20) _
                 From b In Enumerable.Range(a, 21 - a) _
                 From c In Enumerable.Range(b, 21 - b) _
                 Where a * a + b * b = c * c _
                 Select New With { a, b, c }
        
        For Each t In ts
            System.Console.WriteLine("{0}, {1}, {2}", t.a, t.b, t.c)
        Next
    End Sub
End Module
Task: List comprehensions




Go: package main

import "fmt"

type (
    seq  []int
    sofs []seq
)

func newSeq(start, end int) seq {
    if end < start {
        end = start
    }
    s := make(seq, end-start+1)
    for i := 0; i < len(s); i++ {
        s[i] = start + i
    }
    return s
}

func newSofs() sofs {
    return sofs{seq{}}
}

func (s sofs) listComp(in seq, expr func(sofs, seq) sofs, pred func(seq) bool) sofs {
    var s2 sofs
    for _, t := range expr(s, in) {
        if pred(t) {
            s2 = append(s2, t)
        }
    }
    return s2
}

func (s sofs) build(t seq) sofs {
    var u sofs
    for _, ss := range s {
        for _, tt := range t {
            uu := make(seq, len(ss))
            copy(uu, ss)
            uu = append(uu, tt)
            u = append(u, uu)
        }
    }
    return u
}

func main() {
    pt := newSofs()
    in := newSeq(1, 20)
    expr := func(s sofs, t seq) sofs {
        return s.build(t).build(t).build(t)
    }
    pred := func(t seq) bool {
        if len(t) != 3 {
            return false
        }
        return t[0]*t[0]+t[1]*t[1] == t[2]*t[2] && t[0] < t[1] && t[1] < t[2]
    }
    pt = pt.listComp(in, expr, pred)
    fmt.Println(pt)
}
Task: List comprehensions



C#: using System.Linq;

static class Program
{
  static void Main()
  {
    var ts =
      from a in Enumerable.Range(1, 20)
      from b in Enumerable.Range(a, 21 - a)
      from c in Enumerable.Range(b, 21 - b)
      where a * a + b * b == c * c
      select new { a, b, c };

      foreach (var t in ts)
        System.Console.WriteLine("{0}, {1}, {2}", t.a, t.b, t.c);
  }
}








Fortran: 












 
program list_comprehension
  integer, parameter :: n = 20
  integer, parameter :: m = n*(n+1)/2
  integer :: i, j
  complex, dimension(m) :: a
  real, dimension(m) :: b
  logical, dimension(m) :: c
  integer, dimension(3, m) :: d
  a = [ ( ( cmplx(i,j), i=j,n), j=1,n) ] 
  b = abs(a)
  c = (b .eq. int(b)) .and. (b .le. n)
  i = sum(merge(1,0,c))
  d(2,:i) = int(real(pack(a, c))) 
  d(1,:i) = int(imag(pack(a, c))) 
  d(3,:i) = int(pack(b,c))
  print '(3i4)',d(:,:i)
end program list_comprehension
Task: List comprehensions


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

void list_comprehension( std::vector<int> & , int ) ;

int main( ) {
   std::vector<int> triangles ;
   list_comprehension( triangles , 20 ) ;
   std::copy( triangles.begin( ) , triangles.end( ) ,
	 std::ostream_iterator<int>( std::cout , " " ) ) ;
   std::cout << std::endl ;
   return 0 ;
}

void list_comprehension( std::vector<int> & numbers , int upper_border ) {
   for ( int a = 1 ; a < upper_border ; a++ ) {
      for ( int b = a + 1 ; b < upper_border ; b++ ) {
	 double c = pow( a * a + b * b , 0.5 ) ; 
	 if ( ( c * c ) < pow( upper_border , 2 ) + 1 ) {
	    if ( c == floor( c ) ) {
	       numbers.push_back( a ) ;
	       numbers.push_back( b ) ;	      
	       numbers.push_back( static_cast<int>( c ) ) ;
	    }
	 }
      }
   }
}









Fortran: 












 
program list_comprehension
  integer, parameter :: n = 20
  integer, parameter :: m = n*(n+1)/2
  integer :: i, j
  complex, dimension(m) :: a
  real, dimension(m) :: b
  logical, dimension(m) :: c
  integer, dimension(3, m) :: d
  a = [ ( ( cmplx(i,j), i=j,n), j=1,n) ] 
  b = abs(a)
  c = (b .eq. int(b)) .and. (b .le. n)
  i = sum(merge(1,0,c))
  d(2,:i) = int(real(pack(a, c))) 
  d(1,:i) = int(imag(pack(a, c))) 
  d(3,:i) = int(pack(b,c))
  print '(3i4)',d(:,:i)
end program list_comprehension
Task: List comprehensions

C: for (int i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); }










Fortran: 












 
program list_comprehension
  integer, parameter :: n = 20
  integer, parameter :: m = n*(n+1)/2
  integer :: i, j
  complex, dimension(m) :: a
  real, dimension(m) :: b
  logical, dimension(m) :: c
  integer, dimension(3, m) :: d
  a = [ ( ( cmplx(i,j), i=j,n), j=1,n) ] 
  b = abs(a)
  c = (b .eq. int(b)) .and. (b .le. n)
  i = sum(merge(1,0,c))
  d(2,:i) = int(real(pack(a, c))) 
  d(1,:i) = int(imag(pack(a, c))) 
  d(3,:i) = int(pack(b,c))
  print '(3i4)',d(:,:i)
end program list_comprehension
Task: List comprehensions





Java: 
import java.util.Arrays;
import java.util.List;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toList;
import static java.util.stream.IntStream.range;
public interface PythagComp{
    static void main(String... args){
        System.out.println(run(20));
    }

    static List<List<Integer>> run(int n){
        return
            
            
            range(1, n).mapToObj(
                x -> range(x, n).mapToObj(
                    y -> range(y, n).mapToObj(
                        z -> new Integer[]{x, y, z}
                    )
                )
            )
                .flatMap(identity())
                .flatMap(identity())
                
                .filter(a -> a[0]*a[0] + a[1]*a[1] == a[2]*a[2])
                
                .map(Arrays::asList)
                
                .collect(toList())
        ;
    }
}






Fortran: 












 
program list_comprehension
  integer, parameter :: n = 20
  integer, parameter :: m = n*(n+1)/2
  integer :: i, j
  complex, dimension(m) :: a
  real, dimension(m) :: b
  logical, dimension(m) :: c
  integer, dimension(3, m) :: d
  a = [ ( ( cmplx(i,j), i=j,n), j=1,n) ] 
  b = abs(a)
  c = (b .eq. int(b)) .and. (b .le. n)
  i = sum(merge(1,0,c))
  d(2,:i) = int(real(pack(a, c))) 
  d(1,:i) = int(imag(pack(a, c))) 
  d(3,:i) = int(pack(b,c))
  print '(3i4)',d(:,:i)
end program list_comprehension
Task: List comprehensions







Python: [(x,y,z) for x in xrange(1,n+1) for y in xrange(x,n+1) for z in xrange(y,n+1) if x**2 + y**2 == z**2]




Fortran: 












 
program list_comprehension
  integer, parameter :: n = 20
  integer, parameter :: m = n*(n+1)/2
  integer :: i, j
  complex, dimension(m) :: a
  real, dimension(m) :: b
  logical, dimension(m) :: c
  integer, dimension(3, m) :: d
  a = [ ( ( cmplx(i,j), i=j,n), j=1,n) ] 
  b = abs(a)
  c = (b .eq. int(b)) .and. (b .le. n)
  i = sum(merge(1,0,c))
  d(2,:i) = int(real(pack(a, c))) 
  d(1,:i) = int(imag(pack(a, c))) 
  d(3,:i) = int(pack(b,c))
  print '(3i4)',d(:,:i)
end program list_comprehension
Task: List comprehensions








VB: Module ListComp
    Sub Main()
        Dim ts = From a In Enumerable.Range(1, 20) _
                 From b In Enumerable.Range(a, 21 - a) _
                 From c In Enumerable.Range(b, 21 - b) _
                 Where a * a + b * b = c * c _
                 Select New With { a, b, c }
        
        For Each t In ts
            System.Console.WriteLine("{0}, {1}, {2}", t.a, t.b, t.c)
        Next
    End Sub
End Module



Fortran: 












 
program list_comprehension
  integer, parameter :: n = 20
  integer, parameter :: m = n*(n+1)/2
  integer :: i, j
  complex, dimension(m) :: a
  real, dimension(m) :: b
  logical, dimension(m) :: c
  integer, dimension(3, m) :: d
  a = [ ( ( cmplx(i,j), i=j,n), j=1,n) ] 
  b = abs(a)
  c = (b .eq. int(b)) .and. (b .le. n)
  i = sum(merge(1,0,c))
  d(2,:i) = int(real(pack(a, c))) 
  d(1,:i) = int(imag(pack(a, c))) 
  d(3,:i) = int(pack(b,c))
  print '(3i4)',d(:,:i)
end program list_comprehension
Task: Literals_Floating point



C#: double d = 1;
d = 1d;
d = 1D;
d = 1.2; 
d = 1.2d; 
d = .2;
d = 12e-12;
d = 12E-12;
d = 1_234e-1_2; 
float f = 1;
f = 1f;
f = 1F;
f = 1.2f;
f = .2f;
f = 12e-12f;
f = 12E-12f;
f = 1_234e-1_2f;
decimal m = 1;
m = 1m;
m = 1m;
m = 1.2m;
m = .2m;
m = 12e-12m;
m = 12E-12m;
m = 1_234e-1_2m;









Ada: 3.141_592_6
1.0E-12
0.13
Task: Literals_Floating point


C++: #include <iostream>

int main()
{
  
  auto double1 = 2.5;

  
  auto float1 = 2.5f;

  
  auto longdouble1 = 2.5l;

  
  auto double2 = 2.5e-3;
  auto float2 = 2.5e3f;

  
  auto double3 = 0x1p4;
  auto float3 = 0xbeefp-8f;

  std::cout << "\ndouble1: " << double1;
  std::cout << "\nfloat1: " << float1;
  std::cout << "\nlongdouble1: " << longdouble1;
  std::cout << "\ndouble2: " << double2;
  std::cout << "\nfloat2: " << float2;
  std::cout << "\ndouble3: " << double3;
  std::cout << "\nfloat3: " << float3;
  std::cout << "\n";
}










Ada: 3.141_592_6
1.0E-12
0.13
Task: Literals_Floating point





Java: 1. 
1.0 
2432311.7567374 
1.234E-10 
1.234e-10 
758832d 
728832f 
1.0f 
758832D 
728832F 
1.0F 
1 / 2. 
1 / 2 







Ada: 3.141_592_6
1.0E-12
0.13
Task: Literals_Floating point







Python: 2.3    
.3     
.3e4   
.3e+34 
.3e-34 
2.e34  





Ada: 3.141_592_6
1.0E-12
0.13
Task: Literals_Floating point








VB: Sub Main()
Dim d As Double 
Dim s As Single 
  d = -12.3456
  d = 1000#
  d = 0.00001
  d = 67#
  d = 8.9
  d = 0.33
  d = 0#
  d = 2# * 10 ^ 3
  d = 2E+50
  d = 2E-50
  s = -12.3456!
  s = 1000!
  s = 0.00001!
  s = 67!
  s = 8.9!
  s = 0.33!
  s = 0!
  s = 2! * 10 ^ 3
End Sub




Ada: 3.141_592_6
1.0E-12
0.13
Task: Literals_Floating point



C#: double d = 1;
d = 1d;
d = 1D;
d = 1.2; 
d = 1.2d; 
d = .2;
d = 12e-12;
d = 12E-12;
d = 1_234e-1_2; 
float f = 1;
f = 1f;
f = 1F;
f = 1.2f;
f = .2f;
f = 12e-12f;
f = 12E-12f;
f = 1_234e-1_2f;
decimal m = 1;
m = 1m;
m = 1m;
m = 1.2m;
m = .2m;
m = 12e-12m;
m = 12E-12m;
m = 1_234e-1_2m;
Task: Literals_Floating point


C++: #include <iostream>

int main()
{
  
  auto double1 = 2.5;

  
  auto float1 = 2.5f;

  
  auto longdouble1 = 2.5l;

  
  auto double2 = 2.5e-3;
  auto float2 = 2.5e3f;

  
  auto double3 = 0x1p4;
  auto float3 = 0xbeefp-8f;

  std::cout << "\ndouble1: " << double1;
  std::cout << "\nfloat1: " << float1;
  std::cout << "\nlongdouble1: " << longdouble1;
  std::cout << "\ndouble2: " << double2;
  std::cout << "\nfloat2: " << float2;
  std::cout << "\ndouble3: " << double3;
  std::cout << "\nfloat3: " << float3;
  std::cout << "\n";
}
Task: Literals_Floating point





Java: 1. 
1.0 
2432311.7567374 
1.234E-10 
1.234e-10 
758832d 
728832f 
1.0f 
758832D 
728832F 
1.0F 
1 / 2. 
1 / 2
Task: Literals_Floating point







Python: 2.3    
.3     
.3e4   
.3e+34 
.3e-34 
2.e34
Task: Literals_Floating point








VB: Sub Main()
Dim d As Double 
Dim s As Single 
  d = -12.3456
  d = 1000#
  d = 0.00001
  d = 67#
  d = 8.9
  d = 0.33
  d = 0#
  d = 2# * 10 ^ 3
  d = 2E+50
  d = 2E-50
  s = -12.3456!
  s = 1000!
  s = 0.00001!
  s = 67!
  s = 8.9!
  s = 0.33!
  s = 0!
  s = 2! * 10 ^ 3
End Sub
Task: Literals_Floating point






PHP: .12
0.1234
1.2e3
7E-10
Task: Literals_Floating point






PHP: .12
0.1234
1.2e3
7E-10






Ada: 3.141_592_6
1.0E-12
0.13
Task: Abundant odd numbers



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

public static class AbundantOddNumbers
{
    public static void Main() {
        WriteLine("First 25 abundant odd numbers:");
        foreach (var x in AbundantNumbers().Take(25)) WriteLine(x.Format());
        WriteLine();
        WriteLine($"The 1000th abundant odd number: {AbundantNumbers().ElementAt(999).Format()}");
        WriteLine();
        WriteLine($"First abundant odd number > 1b: {AbundantNumbers(1_000_000_001).First().Format()}");
    }

    static IEnumerable<(int n, int sum)> AbundantNumbers(int start = 3) =>
        start.UpBy(2).Select(n => (n, sum: n.DivisorSum())).Where(x => x.sum > x.n);

    static int DivisorSum(this int n) => 3.UpBy(2).TakeWhile(i => i * i <= n).Where(i => n % i == 0)
        .Select(i => (a:i, b:n/i)).Sum(p => p.a == p.b ? p.a : p.a + p.b) + 1;

    static IEnumerable<int> UpBy(this int n, int step) {
        for (int i = n; ; i+=step) yield return i;
    }

    static string Format(this (int n, int sum) pair) => $"{pair.n:N0} with sum {pair.sum:N0}";
}









Ada: with Ada.Text_IO, Generic_Divisors;

procedure Odd_Abundant is
   function Same(P: Positive) return Positive is (P);
   
   package Divisor_Sum is new Generic_Divisors
     (Result_Type => Natural, None => 0, One => Same, Add =>  "+");
   
   function Abundant(N: Positive) return Boolean is
      (Divisor_Sum.Process(N) > N);
      
   package NIO is new Ada.Text_IO.Integer_IO(Natural);
   
   Current: Positive := 1;
   
   procedure Print_Abundant_Line
     (Idx: Positive; N: Positive; With_Idx: Boolean:= True) is
   begin
      if With_Idx then 
	 NIO.Put(Idx, 6);  Ada.Text_IO.Put(" |");
      else
	 Ada.Text_IO.Put("   *** |");
      end if;
      NIO.Put(N, 12); Ada.Text_IO.Put(" | "); 
      NIO.Put(Divisor_Sum.Process(N), 12); Ada.Text_IO.New_Line;
   end Print_Abundant_Line;      
   
begin
   
   Ada.Text_IO.Put_Line(" index |      number | proper divisor sum ");
   Ada.Text_IO.Put_Line("
   for I in 1 .. 25 loop
      while not Abundant(Current) loop
	 Current := Current + 2;
      end loop;
      Print_Abundant_Line(I, Current);
      Current := Current + 2;
   end loop;
   
   
   Ada.Text_IO.Put_Line("
   for I in 26 .. 1_000 loop
      Current := Current + 2;
      while not Abundant(Current) loop
	 Current := Current + 2;
      end loop;
   end loop;
   Print_Abundant_Line(1000, Current);
   
   
   Ada.Text_IO.Put_Line("
   Current := 10**9+1;
   while not Abundant(Current) loop
      Current := Current + 2;
   end loop;
   Print_Abundant_Line(1, Current, False);
end Odd_Abundant;
Task: Abundant odd numbers

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



unsigned sum_proper_divisors(const unsigned n) {
  unsigned sum = 1;
  for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j);
  return sum;
}

int main(int argc, char const *argv[]) {
  unsigned n, c;
  for (n = 1, c = 0; c < 25; n += 2) if (n < sum_proper_divisors(n)) printf("%u: %u\n", ++c, n);

  for ( ; c < 1000; n += 2) if (n < sum_proper_divisors(n)) c ++;
  printf("\nThe one thousandth abundant odd number is: %u\n", n);

  for (n = 1000000001 ;; n += 2) if (n < sum_proper_divisors(n)) break;
  printf("The first abundant odd number above one billion is: %u\n", n);
  
  return 0;
}











Ada: with Ada.Text_IO, Generic_Divisors;

procedure Odd_Abundant is
   function Same(P: Positive) return Positive is (P);
   
   package Divisor_Sum is new Generic_Divisors
     (Result_Type => Natural, None => 0, One => Same, Add =>  "+");
   
   function Abundant(N: Positive) return Boolean is
      (Divisor_Sum.Process(N) > N);
      
   package NIO is new Ada.Text_IO.Integer_IO(Natural);
   
   Current: Positive := 1;
   
   procedure Print_Abundant_Line
     (Idx: Positive; N: Positive; With_Idx: Boolean:= True) is
   begin
      if With_Idx then 
	 NIO.Put(Idx, 6);  Ada.Text_IO.Put(" |");
      else
	 Ada.Text_IO.Put("   *** |");
      end if;
      NIO.Put(N, 12); Ada.Text_IO.Put(" | "); 
      NIO.Put(Divisor_Sum.Process(N), 12); Ada.Text_IO.New_Line;
   end Print_Abundant_Line;      
   
begin
   
   Ada.Text_IO.Put_Line(" index |      number | proper divisor sum ");
   Ada.Text_IO.Put_Line("
   for I in 1 .. 25 loop
      while not Abundant(Current) loop
	 Current := Current + 2;
      end loop;
      Print_Abundant_Line(I, Current);
      Current := Current + 2;
   end loop;
   
   
   Ada.Text_IO.Put_Line("
   for I in 26 .. 1_000 loop
      Current := Current + 2;
      while not Abundant(Current) loop
	 Current := Current + 2;
      end loop;
   end loop;
   Print_Abundant_Line(1000, Current);
   
   
   Ada.Text_IO.Put_Line("
   Current := 10**9+1;
   while not Abundant(Current) loop
      Current := Current + 2;
   end loop;
   Print_Abundant_Line(1, Current, False);
end Odd_Abundant;