WeixiangYan/CodeTransOcean huggingface dataset:
Task: Bell numbers







Python: def bellTriangle(n):
    tri = [None] * n
    for i in xrange(n):
        tri[i] = [0] * i
    tri[1][0] = 1
    for i in xrange(2, n):
        tri[i][0] = tri[i - 1][i - 2]
        for j in xrange(1, i):
            tri[i][j] = tri[i][j - 1] + tri[i - 1][j - 1]
    return tri

def main():
    bt = bellTriangle(51)
    print "First fifteen and fiftieth Bell numbers:"
    for i in xrange(1, 16):
        print "%2d: %d" % (i, bt[i][0])
    print "50:", bt[50][0]
    print
    print "The first ten rows of Bell's triangle:"
    for i in xrange(1, 11):
        print bt[i]

main()





Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
	type Bell_Triangle is array(Positive range <>, Positive range <>) of Natural;
	
	
	procedure Print_Rows (Row : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Row in Triangle'Range(1) then
				for I in Triangle'First(1) .. Row loop
					Put_Line (Triangle (I, 1)'Image);
				end loop;
			end if;
	end Print_Rows;
	
	procedure Print_Triangle (Num : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Num in Triangle'Range then
				for I in Triangle'First(1) .. Num loop
					for J in Triangle'First(2) .. Num loop
						if Triangle (I, J) /= 0 then
							Put (Triangle (I, J)'Image);
						end if;
					end loop;
					New_Line;
				end loop;
			end if;
	end Print_Triangle;
	
	procedure Bell_Numbers is
		Triangle : Bell_Triangle(1..15, 1..15) := (Others => (Others => 0));
		Temp     : Positive := 1;
		begin
			
			Triangle (1, 1) := 1;
			
			for I in Triangle'First(1) + 1 .. Triangle'Last(1) loop
				Triangle (I, 1) := Temp;
				
				for J in Triangle'First(2) .. Triangle'Last(2) - 1 loop
					if Triangle (I - 1, J) /= 0 then
						Triangle (I, J + 1) := Triangle (I, J) + Triangle (I - 1, J);
					else
						Temp := Triangle (I, J);
						exit;
					end if;
				end loop;
			end loop;
			
			Put_Line ("First 15 Bell numbers:");
			Print_Rows (15, Triangle);
			
			New_Line;
			
			Put_Line ("First 10 rows of the Bell triangle:");
			Print_Triangle (10, Triangle);
	end Bell_Numbers;
begin
	Bell_Numbers;
end Main;
Task: Bell numbers








VB: Imports System.Numerics
Imports System.Runtime.CompilerServices

Module Module1

    <Extension()>
    Sub Init(Of T)(array As T(), value As T)
        If IsNothing(array) Then Return
        For i = 0 To array.Length - 1
            array(i) = value
        Next
    End Sub

    Function BellTriangle(n As Integer) As BigInteger()()
        Dim tri(n - 1)() As BigInteger
        For i = 0 To n - 1
            Dim temp(i - 1) As BigInteger
            tri(i) = temp
            tri(i).Init(0)
        Next
        tri(1)(0) = 1
        For i = 2 To n - 1
            tri(i)(0) = tri(i - 1)(i - 2)
            For j = 1 To i - 1
                tri(i)(j) = tri(i)(j - 1) + tri(i - 1)(j - 1)
            Next
        Next
        Return tri
    End Function

    Sub Main()
        Dim bt = BellTriangle(51)
        Console.WriteLine("First fifteen Bell numbers:")
        For i = 1 To 15
            Console.WriteLine("{0,2}: {1}", i, bt(i)(0))
        Next
        Console.WriteLine("50: {0}", bt(50)(0))
        Console.WriteLine()
        Console.WriteLine("The first ten rows of Bell
        For i = 1 To 10
            Dim it = bt(i).GetEnumerator()
            Console.Write("[")
            If it.MoveNext() Then
                Console.Write(it.Current)
            End If
            While it.MoveNext()
                Console.Write(", ")
                Console.Write(it.Current)
            End While
            Console.WriteLine("]")
        Next
    End Sub

End Module




Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
	type Bell_Triangle is array(Positive range <>, Positive range <>) of Natural;
	
	
	procedure Print_Rows (Row : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Row in Triangle'Range(1) then
				for I in Triangle'First(1) .. Row loop
					Put_Line (Triangle (I, 1)'Image);
				end loop;
			end if;
	end Print_Rows;
	
	procedure Print_Triangle (Num : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Num in Triangle'Range then
				for I in Triangle'First(1) .. Num loop
					for J in Triangle'First(2) .. Num loop
						if Triangle (I, J) /= 0 then
							Put (Triangle (I, J)'Image);
						end if;
					end loop;
					New_Line;
				end loop;
			end if;
	end Print_Triangle;
	
	procedure Bell_Numbers is
		Triangle : Bell_Triangle(1..15, 1..15) := (Others => (Others => 0));
		Temp     : Positive := 1;
		begin
			
			Triangle (1, 1) := 1;
			
			for I in Triangle'First(1) + 1 .. Triangle'Last(1) loop
				Triangle (I, 1) := Temp;
				
				for J in Triangle'First(2) .. Triangle'Last(2) - 1 loop
					if Triangle (I - 1, J) /= 0 then
						Triangle (I, J + 1) := Triangle (I, J) + Triangle (I - 1, J);
					else
						Temp := Triangle (I, J);
						exit;
					end if;
				end loop;
			end loop;
			
			Put_Line ("First 15 Bell numbers:");
			Print_Rows (15, Triangle);
			
			New_Line;
			
			Put_Line ("First 10 rows of the Bell triangle:");
			Print_Triangle (10, Triangle);
	end Bell_Numbers;
begin
	Bell_Numbers;
end Main;
Task: Bell numbers

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


size_t bellIndex(int row, int col) {
    return row * (row - 1) / 2 + col;
}

int getBell(int *bellTri, int row, int col) {
    size_t index = bellIndex(row, col);
    return bellTri[index];
}

void setBell(int *bellTri, int row, int col, int value) {
    size_t index = bellIndex(row, col);
    bellTri[index] = value;
}

int *bellTriangle(int n) {
    size_t length = n * (n + 1) / 2;
    int *tri = calloc(length, sizeof(int));
    int i, j;

    setBell(tri, 1, 0, 1);
    for (i = 2; i <= n; ++i) {
        setBell(tri, i, 0, getBell(tri, i - 1, i - 2));
        for (j = 1; j < i; ++j) {
            int value = getBell(tri, i, j - 1) + getBell(tri, i - 1, j - 1);
            setBell(tri, i, j, value);
        }
    }

    return tri;
}

int main() {
    const int rows = 15;
    int *bt = bellTriangle(rows);
    int i, j;

    printf("First fifteen Bell numbers:\n");
    for (i = 1; i <= rows; ++i) {
        printf("%2d: %d\n", i, getBell(bt, i, 0));
    }

    printf("\nThe first ten rows of Bell's triangle:\n");
    for (i = 1; i <= 10; ++i) {
        printf("%d", getBell(bt, i, 0));
        for (j = 1; j < i; ++j) {
            printf(", %d", getBell(bt, i, j));
        }
        printf("\n");
    }

    free(bt);
    return 0;
}
Task: Bell numbers



C#: using System;
using System.Numerics;

namespace BellNumbers {
    public static class Utility {
        public static void Init<T>(this T[] array, T value) {
            if (null == array) return;
            for (int i = 0; i < array.Length; ++i) {
                array[i] = value;
            }
        }
    }

    class Program {
        static BigInteger[][] BellTriangle(int n) {
            BigInteger[][] tri = new BigInteger[n][];
            for (int i = 0; i < n; ++i) {
                tri[i] = new BigInteger[i];
                tri[i].Init(BigInteger.Zero);
            }
            tri[1][0] = 1;
            for (int i = 2; i < n; ++i) {
                tri[i][0] = tri[i - 1][i - 2];
                for (int j = 1; j < i; ++j) {
                    tri[i][j] = tri[i][j - 1] + tri[i - 1][j - 1];
                }
            }
            return tri;
        }

        static void Main(string[] args) {
            var bt = BellTriangle(51);
            Console.WriteLine("First fifteen and fiftieth Bell numbers:");
            for (int i = 1; i < 16; ++i) {
                Console.WriteLine("{0,2}: {1}", i, bt[i][0]);
            }
            Console.WriteLine("50: {0}", bt[50][0]);
            Console.WriteLine();
            Console.WriteLine("The first ten rows of Bell's triangle:");
            for (int i = 1; i < 11; ++i) {
                
                var it = bt[i].GetEnumerator();
                Console.Write("[");
                if (it.MoveNext()) {
                    Console.Write(it.Current);
                }
                while (it.MoveNext()) {
                    Console.Write(", ");
                    Console.Write(it.Current);
                }
                Console.WriteLine("]");
            }
        }
    }
}
Task: Bell numbers


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

#ifdef HAVE_BOOST
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int integer;
#else
typedef unsigned int integer;
#endif

auto make_bell_triangle(int n) {
    std::vector<std::vector<integer>> bell(n);
    for (int i = 0; i < n; ++i)
        bell[i].assign(i + 1, 0);
    bell[0][0] = 1;
    for (int i = 1; i < n; ++i) {
        std::vector<integer>& row = bell[i];
        std::vector<integer>& prev_row = bell[i - 1];
        row[0] = prev_row[i - 1];
        for (int j = 1; j <= i; ++j)
            row[j] = row[j - 1] + prev_row[j - 1];
    }
    return bell;
}

int main() {
#ifdef HAVE_BOOST
    const int size = 50;
#else
    const int size = 15;
#endif
    auto bell(make_bell_triangle(size));
    
    const int limit = 15;
    std::cout << "First " << limit << " Bell numbers:\n";
    for (int i = 0; i < limit; ++i)
        std::cout << bell[i][0] << '\n';

#ifdef HAVE_BOOST
    std::cout << "\n50th Bell number is " << bell[49][0] << "\n\n";
#endif

    std::cout << "First 10 rows of the Bell triangle:\n";
    for (int i = 0; i < 10; ++i) {
        std::cout << bell[i][0];
        for (int j = 1; j <= i; ++j)
            std::cout << ' ' << bell[i][j];
        std::cout << '\n';
    }
    return 0;
}
Task: Bell numbers





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

public class Bell {
    private static class BellTriangle {
        private List<Integer> arr;

        BellTriangle(int n) {
            int length = n * (n + 1) / 2;
            arr = new ArrayList<>(length);
            for (int i = 0; i < length; ++i) {
                arr.add(0);
            }

            set(1, 0, 1);
            for (int i = 2; i <= n; ++i) {
                set(i, 0, get(i - 1, i - 2));
                for (int j = 1; j < i; ++j) {
                    int value = get(i, j - 1) + get(i - 1, j - 1);
                    set(i, j, value);
                }
            }
        }

        private int index(int row, int col) {
            if (row > 0 && col >= 0 && col < row) {
                return row * (row - 1) / 2 + col;
            } else {
                throw new IllegalArgumentException();
            }
        }

        public int get(int row, int col) {
            int i = index(row, col);
            return arr.get(i);
        }

        public void set(int row, int col, int value) {
            int i = index(row, col);
            arr.set(i, value);
        }
    }

    public static void main(String[] args) {
        final int rows = 15;
        BellTriangle bt = new BellTriangle(rows);

        System.out.println("First fifteen Bell numbers:");
        for (int i = 0; i < rows; ++i) {
            System.out.printf("%2d: %d\n", i + 1, bt.get(i + 1, 0));
        }

        for (int i = 1; i <= 10; ++i) {
            System.out.print(bt.get(i, 0));
            for (int j = 1; j < i; ++j) {
                System.out.printf(", %d", bt.get(i, j));
            }
            System.out.println();
        }
    }
}
Task: Bell numbers







Python: def bellTriangle(n):
    tri = [None] * n
    for i in xrange(n):
        tri[i] = [0] * i
    tri[1][0] = 1
    for i in xrange(2, n):
        tri[i][0] = tri[i - 1][i - 2]
        for j in xrange(1, i):
            tri[i][j] = tri[i][j - 1] + tri[i - 1][j - 1]
    return tri

def main():
    bt = bellTriangle(51)
    print "First fifteen and fiftieth Bell numbers:"
    for i in xrange(1, 16):
        print "%2d: %d" % (i, bt[i][0])
    print "50:", bt[50][0]
    print
    print "The first ten rows of Bell's triangle:"
    for i in xrange(1, 11):
        print bt[i]

main()
Task: Bell numbers








VB: Imports System.Numerics
Imports System.Runtime.CompilerServices

Module Module1

    <Extension()>
    Sub Init(Of T)(array As T(), value As T)
        If IsNothing(array) Then Return
        For i = 0 To array.Length - 1
            array(i) = value
        Next
    End Sub

    Function BellTriangle(n As Integer) As BigInteger()()
        Dim tri(n - 1)() As BigInteger
        For i = 0 To n - 1
            Dim temp(i - 1) As BigInteger
            tri(i) = temp
            tri(i).Init(0)
        Next
        tri(1)(0) = 1
        For i = 2 To n - 1
            tri(i)(0) = tri(i - 1)(i - 2)
            For j = 1 To i - 1
                tri(i)(j) = tri(i)(j - 1) + tri(i - 1)(j - 1)
            Next
        Next
        Return tri
    End Function

    Sub Main()
        Dim bt = BellTriangle(51)
        Console.WriteLine("First fifteen Bell numbers:")
        For i = 1 To 15
            Console.WriteLine("{0,2}: {1}", i, bt(i)(0))
        Next
        Console.WriteLine("50: {0}", bt(50)(0))
        Console.WriteLine()
        Console.WriteLine("The first ten rows of Bell
        For i = 1 To 10
            Dim it = bt(i).GetEnumerator()
            Console.Write("[")
            If it.MoveNext() Then
                Console.Write(it.Current)
            End If
            While it.MoveNext()
                Console.Write(", ")
                Console.Write(it.Current)
            End While
            Console.WriteLine("]")
        Next
    End Sub

End Module
Task: Bell numbers




Go: package main

import (
    "fmt"
    "math/big"
)

func bellTriangle(n int) [][]*big.Int {
    tri := make([][]*big.Int, n)
    for i := 0; i < n; i++ {
        tri[i] = make([]*big.Int, i)
        for j := 0; j < i; j++ {
            tri[i][j] = new(big.Int)
        }
    }
    tri[1][0].SetUint64(1)
    for i := 2; i < n; i++ {
        tri[i][0].Set(tri[i-1][i-2])
        for j := 1; j < i; j++ {
            tri[i][j].Add(tri[i][j-1], tri[i-1][j-1])
        }
    }
    return tri
}

func main() {
    bt := bellTriangle(51)
    fmt.Println("First fifteen and fiftieth Bell numbers:")
    for i := 1; i <= 15; i++ {
        fmt.Printf("%2d: %d\n", i, bt[i][0])
    }
    fmt.Println("50:", bt[50][0])
    fmt.Println("\nThe first ten rows of Bell's triangle:")
    for i := 1; i <= 10; i++ {
        fmt.Println(bt[i])
    }    
}
Task: Modular exponentiation



C#: using System;
using System.Numerics;

class Program
{
    static void Main() {
        var a = BigInteger.Parse("2988348162058574136915891421498819466320163312926952423791023078876139");
        var b = BigInteger.Parse("2351399303373464486466122544523690094744975233415544072992656881240319");
        var m = BigInteger.Pow(10, 40);
        Console.WriteLine(BigInteger.ModPow(a, b, m));
    }
}









Ada: with Ada.Text_IO, Ada.Command_Line, Crypto.Types.Big_Numbers;

procedure Mod_Exp is

   A: String :=
     "2988348162058574136915891421498819466320163312926952423791023078876139";
   B: String :=
     "2351399303373464486466122544523690094744975233415544072992656881240319";

   D: constant Positive := Positive'Max(Positive'Max(A'Length, B'Length), 40);
     
   Bits: constant Positive := (34*D)/10;
     
   package LN is new Crypto.Types.Big_Numbers (Bits + (32 - Bits mod 32));
     
   use type LN.Big_Unsigned;

   function "+"(S: String) return LN.Big_Unsigned
     renames LN.Utils.To_Big_Unsigned;

   M: LN.Big_Unsigned := (+"10") ** (+"40");

begin
   Ada.Text_IO.Put("A**B (mod 10**40) = ");
   Ada.Text_IO.Put_Line(LN.Utils.To_String(LN.Mod_Utils.Pow((+A), (+B), M)));
end Mod_Exp;
Task: Modular exponentiation

C: #include <gmp.h>

int main()
{
	mpz_t a, b, m, r;

	mpz_init_set_str(a,	"2988348162058574136915891421498819466320"
				"163312926952423791023078876139", 0);
	mpz_init_set_str(b,	"2351399303373464486466122544523690094744"
				"975233415544072992656881240319", 0);
	mpz_init(m);
	mpz_ui_pow_ui(m, 10, 40);

	mpz_init(r);
	mpz_powm(r, a, b, m);

	gmp_printf("%Zd\n", r); 

	mpz_clear(a);
	mpz_clear(b);
	mpz_clear(m);
	mpz_clear(r);

	return 0;
}











Ada: with Ada.Text_IO, Ada.Command_Line, Crypto.Types.Big_Numbers;

procedure Mod_Exp is

   A: String :=
     "2988348162058574136915891421498819466320163312926952423791023078876139";
   B: String :=
     "2351399303373464486466122544523690094744975233415544072992656881240319";

   D: constant Positive := Positive'Max(Positive'Max(A'Length, B'Length), 40);
     
   Bits: constant Positive := (34*D)/10;
     
   package LN is new Crypto.Types.Big_Numbers (Bits + (32 - Bits mod 32));
     
   use type LN.Big_Unsigned;

   function "+"(S: String) return LN.Big_Unsigned
     renames LN.Utils.To_Big_Unsigned;

   M: LN.Big_Unsigned := (+"10") ** (+"40");

begin
   Ada.Text_IO.Put("A**B (mod 10**40) = ");
   Ada.Text_IO.Put_Line(LN.Utils.To_String(LN.Mod_Utils.Pow((+A), (+B), M)));
end Mod_Exp;
Task: Modular exponentiation


C++: #include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/integer.hpp>

int main() {
    using boost::multiprecision::cpp_int;
    using boost::multiprecision::pow;
    using boost::multiprecision::powm;
    cpp_int a("2988348162058574136915891421498819466320163312926952423791023078876139");
    cpp_int b("2351399303373464486466122544523690094744975233415544072992656881240319");
    std::cout << powm(a, b, pow(cpp_int(10), 40)) << '\n';
    return 0;
}










Ada: with Ada.Text_IO, Ada.Command_Line, Crypto.Types.Big_Numbers;

procedure Mod_Exp is

   A: String :=
     "2988348162058574136915891421498819466320163312926952423791023078876139";
   B: String :=
     "2351399303373464486466122544523690094744975233415544072992656881240319";

   D: constant Positive := Positive'Max(Positive'Max(A'Length, B'Length), 40);
     
   Bits: constant Positive := (34*D)/10;
     
   package LN is new Crypto.Types.Big_Numbers (Bits + (32 - Bits mod 32));
     
   use type LN.Big_Unsigned;

   function "+"(S: String) return LN.Big_Unsigned
     renames LN.Utils.To_Big_Unsigned;

   M: LN.Big_Unsigned := (+"10") ** (+"40");

begin
   Ada.Text_IO.Put("A**B (mod 10**40) = ");
   Ada.Text_IO.Put_Line(LN.Utils.To_String(LN.Mod_Utils.Pow((+A), (+B), M)));
end Mod_Exp;
Task: Modular exponentiation




Go: package main

import (
    "fmt"
    "math/big"
)

func main() {
    a, _ := new(big.Int).SetString(
        "2988348162058574136915891421498819466320163312926952423791023078876139", 10)
    b, _ := new(big.Int).SetString(
        "2351399303373464486466122544523690094744975233415544072992656881240319", 10)
    m := big.NewInt(10)
    r := big.NewInt(40)
    m.Exp(m, r, nil)

    r.Exp(a, b, m)
    fmt.Println(r)
}








Ada: with Ada.Text_IO, Ada.Command_Line, Crypto.Types.Big_Numbers;

procedure Mod_Exp is

   A: String :=
     "2988348162058574136915891421498819466320163312926952423791023078876139";
   B: String :=
     "2351399303373464486466122544523690094744975233415544072992656881240319";

   D: constant Positive := Positive'Max(Positive'Max(A'Length, B'Length), 40);
     
   Bits: constant Positive := (34*D)/10;
     
   package LN is new Crypto.Types.Big_Numbers (Bits + (32 - Bits mod 32));
     
   use type LN.Big_Unsigned;

   function "+"(S: String) return LN.Big_Unsigned
     renames LN.Utils.To_Big_Unsigned;

   M: LN.Big_Unsigned := (+"10") ** (+"40");

begin
   Ada.Text_IO.Put("A**B (mod 10**40) = ");
   Ada.Text_IO.Put_Line(LN.Utils.To_String(LN.Mod_Utils.Pow((+A), (+B), M)));
end Mod_Exp;
Task: Modular exponentiation





Java: import java.math.BigInteger;

public class PowMod {
    public static void main(String[] args){
        BigInteger a = new BigInteger(
      "2988348162058574136915891421498819466320163312926952423791023078876139");
        BigInteger b = new BigInteger(
      "2351399303373464486466122544523690094744975233415544072992656881240319");
        BigInteger m = new BigInteger("10000000000000000000000000000000000000000");
        
        System.out.println(a.modPow(b, m));
    }
}







Ada: with Ada.Text_IO, Ada.Command_Line, Crypto.Types.Big_Numbers;

procedure Mod_Exp is

   A: String :=
     "2988348162058574136915891421498819466320163312926952423791023078876139";
   B: String :=
     "2351399303373464486466122544523690094744975233415544072992656881240319";

   D: constant Positive := Positive'Max(Positive'Max(A'Length, B'Length), 40);
     
   Bits: constant Positive := (34*D)/10;
     
   package LN is new Crypto.Types.Big_Numbers (Bits + (32 - Bits mod 32));
     
   use type LN.Big_Unsigned;

   function "+"(S: String) return LN.Big_Unsigned
     renames LN.Utils.To_Big_Unsigned;

   M: LN.Big_Unsigned := (+"10") ** (+"40");

begin
   Ada.Text_IO.Put("A**B (mod 10**40) = ");
   Ada.Text_IO.Put_Line(LN.Utils.To_String(LN.Mod_Utils.Pow((+A), (+B), M)));
end Mod_Exp;
Task: Modular exponentiation







Python: a = 2988348162058574136915891421498819466320163312926952423791023078876139
b = 2351399303373464486466122544523690094744975233415544072992656881240319
m = 10 ** 40
print(pow(a, b, m))





Ada: with Ada.Text_IO, Ada.Command_Line, Crypto.Types.Big_Numbers;

procedure Mod_Exp is

   A: String :=
     "2988348162058574136915891421498819466320163312926952423791023078876139";
   B: String :=
     "2351399303373464486466122544523690094744975233415544072992656881240319";

   D: constant Positive := Positive'Max(Positive'Max(A'Length, B'Length), 40);
     
   Bits: constant Positive := (34*D)/10;
     
   package LN is new Crypto.Types.Big_Numbers (Bits + (32 - Bits mod 32));
     
   use type LN.Big_Unsigned;

   function "+"(S: String) return LN.Big_Unsigned
     renames LN.Utils.To_Big_Unsigned;

   M: LN.Big_Unsigned := (+"10") ** (+"40");

begin
   Ada.Text_IO.Put("A**B (mod 10**40) = ");
   Ada.Text_IO.Put_Line(LN.Utils.To_String(LN.Mod_Utils.Pow((+A), (+B), M)));
end Mod_Exp;
Task: Modular exponentiation








VB: 
    Imports System.Numerics

    Private Sub Main()
        Dim a, b, m, x As BigInteger
        a = BigInteger.Parse("2988348162058574136915891421498819466320163312926952423791023078876139")
        b = BigInteger.Parse("2351399303373464486466122544523690094744975233415544072992656881240319")
        m = BigInteger.Pow(10, 40)   
        x = ModPowBig(a, b, m)
        Debug.Print("x=" & x.ToString)
    End Sub 

    Function ModPowBig(ByVal base As BigInteger, ByVal exponent As BigInteger, ByVal modulus As BigInteger) As BigInteger
        Dim result As BigInteger
        result = 1
        Do While exponent > 0
            If (exponent Mod 2) = 1 Then
                result = (result * base) Mod modulus
            End If
            exponent = exponent / 2
            base = (base * base) Mod modulus
        Loop
        Return result
    End Function 




Ada: with Ada.Text_IO, Ada.Command_Line, Crypto.Types.Big_Numbers;

procedure Mod_Exp is

   A: String :=
     "2988348162058574136915891421498819466320163312926952423791023078876139";
   B: String :=
     "2351399303373464486466122544523690094744975233415544072992656881240319";

   D: constant Positive := Positive'Max(Positive'Max(A'Length, B'Length), 40);
     
   Bits: constant Positive := (34*D)/10;
     
   package LN is new Crypto.Types.Big_Numbers (Bits + (32 - Bits mod 32));
     
   use type LN.Big_Unsigned;

   function "+"(S: String) return LN.Big_Unsigned
     renames LN.Utils.To_Big_Unsigned;

   M: LN.Big_Unsigned := (+"10") ** (+"40");

begin
   Ada.Text_IO.Put("A**B (mod 10**40) = ");
   Ada.Text_IO.Put_Line(LN.Utils.To_String(LN.Mod_Utils.Pow((+A), (+B), M)));
end Mod_Exp;
Task: Modular exponentiation

C: #include <gmp.h>

int main()
{
	mpz_t a, b, m, r;

	mpz_init_set_str(a,	"2988348162058574136915891421498819466320"
				"163312926952423791023078876139", 0);
	mpz_init_set_str(b,	"2351399303373464486466122544523690094744"
				"975233415544072992656881240319", 0);
	mpz_init(m);
	mpz_ui_pow_ui(m, 10, 40);

	mpz_init(r);
	mpz_powm(r, a, b, m);

	gmp_printf("%Zd\n", r); 

	mpz_clear(a);
	mpz_clear(b);
	mpz_clear(m);
	mpz_clear(r);

	return 0;
}
Task: Modular exponentiation



C#: using System;
using System.Numerics;

class Program
{
    static void Main() {
        var a = BigInteger.Parse("2988348162058574136915891421498819466320163312926952423791023078876139");
        var b = BigInteger.Parse("2351399303373464486466122544523690094744975233415544072992656881240319");
        var m = BigInteger.Pow(10, 40);
        Console.WriteLine(BigInteger.ModPow(a, b, m));
    }
}