WeixiangYan/CodeTransOcean huggingface dataset:
Task: Inverted index







Python: 

from pprint import pprint as pp
from glob import glob
try: reduce
except: from functools import reduce
try:    raw_input
except: raw_input = input


def parsetexts(fileglob='InvertedIndex/T*.txt'):
    texts, words = {}, set()
    for txtfile in glob(fileglob):
        with open(txtfile, 'r') as f:
            txt = f.read().split()
            words |= set(txt)
            texts[txtfile.split('\\')[-1]] = txt
    return texts, words

def termsearch(terms): 
    return reduce(set.intersection,
                  (invindex[term] for term in terms),
                  set(texts.keys()))

texts, words = parsetexts()
print('\nTexts')
pp(texts)
print('\nWords')
pp(sorted(words))

invindex = {word:set(txt
                        for txt, wrds in texts.items() if word in wrds)
            for word in words}
print('\nInverted Index')
pp({k:sorted(v) for k,v in invindex.items()})

terms = ["what", "is", "it"]
print('\nTerm Search for: ' + repr(terms))
pp(sorted(termsearch(terms)))
Task: Inverted index




Go: package main

import (
    "bufio"
    "bytes"
    "errors"
    "fmt"
    "io"
    "os"
)


var index map[string][]int 
var indexed []doc

type doc struct {
    file  string
    title string
}

func main() {
    
    index = make(map[string][]int)

    
    if err := indexDir("docs"); err != nil {
        fmt.Println(err)
        return
    }

    
    ui()
}

func indexDir(dir string) error {
    df, err := os.Open(dir)
    if err != nil {
        return err
    }
    fis, err := df.Readdir(-1)
    if err != nil {
        return err
    }
    if len(fis) == 0 {
        return errors.New(fmt.Sprintf("no files in %s", dir))
    }
    indexed := 0
    for _, fi := range fis {
        if !fi.IsDir() {
            if indexFile(dir + "/" + fi.Name()) {
                indexed++
            }
        }
    }
    return nil
}

func indexFile(fn string) bool {
    f, err := os.Open(fn)
    if err != nil {
        fmt.Println(err)
        return false 
    }

    
    x := len(indexed)
    indexed = append(indexed, doc{fn, fn})
    pdoc := &indexed[x]

    
    r := bufio.NewReader(f)
    lines := 0
    for {
        b, isPrefix, err := r.ReadLine()
        switch {
        case err == io.EOF:
            return true
        case err != nil:
            fmt.Println(err)
            return true
        case isPrefix:
            fmt.Printf("%s: unexpected long line\n", fn)
            return true
        case lines < 20 && bytes.HasPrefix(b, []byte("Title:")):
            
            
            
            pdoc.title = string(b[7:])
        }
        
        
        
    wordLoop:
        for _, bword := range bytes.Fields(b) {
            bword := bytes.Trim(bword, ".,-~?!\"'`;:()<>[]{}\\|/=_+*&^%$#@")
            if len(bword) > 0 {
                word := string(bword)
                dl := index[word]
                for _, d := range dl {
                    if d == x {
                        continue wordLoop
                    }
                }
                index[word] = append(dl, x)
            }
        }
    }
    return true
}

func ui() {
    fmt.Println(len(index), "words indexed in", len(indexed), "files")
    fmt.Println("enter single words to search for")
    fmt.Println("enter a blank line when done")
    var word string
    for {
        fmt.Print("search word: ")
        wc, _ := fmt.Scanln(&word)
        if wc == 0 {
            return
        }
        switch dl := index[word]; len(dl) {
        case 0:
            fmt.Println("no match")
        case 1:
            fmt.Println("one match:")
            fmt.Println("   ", indexed[dl[0]].file, indexed[dl[0]].title)
        default:
            fmt.Println(len(dl), "matches:")
            for _, d := range dl {
                fmt.Println("   ", indexed[d].file, indexed[d].title)
            }
        }
    }
}
Task: Inverted index






PHP: <?php

function buildInvertedIndex($filenames)
{
    $invertedIndex = [];

    foreach($filenames as $filename)
    {
        $data = file_get_contents($filename);

        if($data === false) die('Unable to read file: ' . $filename);

        preg_match_all('/(\w+)/', $data, $matches, PREG_SET_ORDER);

        foreach($matches as $match)
        {
            $word = strtolower($match[0]);

            if(!array_key_exists($word, $invertedIndex)) $invertedIndex[$word] = [];
            if(!in_array($filename, $invertedIndex[$word], true)) $invertedIndex[$word][] = $filename;
        }
    }

    return $invertedIndex;
}

function lookupWord($invertedIndex, $word)
{
    return array_key_exists($word, $invertedIndex) ? $invertedIndex[$word] : false;
}

$invertedIndex = buildInvertedIndex2(['file1.txt', 'file2.txt', 'file3.txt']);

foreach(['cat', 'is', 'banana', 'it'] as $word)
{
    $matches = lookupWord($invertedIndex, $word);

    if($matches !== false)
    {
        echo "Found the word \"$word\" in the following files: " . implode(', ', $matches) . "\n";
    }
    else
    {
        echo "Unable to find the word \"$word\" in the index\n";
    }
}
Task: Factors of an integer



C#: static void Main (string[] args) {
    do {
        Console.WriteLine ("Number:");
        Int64 p = 0;
        do {
            try {
                p = Convert.ToInt64 (Console.ReadLine ());
                break;
            } catch (Exception) { }

        } while (true);

        Console.WriteLine ("For 1 through " + ((int) Math.Sqrt (p)).ToString () + "");
        for (int x = 1; x <= (int) Math.Sqrt (p); x++) {
            if (p % x == 0)
                Console.WriteLine ("Found: " + x.ToString () + ". " + p.ToString () + " / " + x.ToString () + " = " + (p / x).ToString ());
        }

        Console.WriteLine ("Done.");
    } while (true);
}









Ada: with Ada.Text_IO;
with Ada.Command_Line;
procedure Factors is
   Number  : Positive;
   Test_Nr : Positive := 1;
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put (Ada.Text_IO.Standard_Error, "Missing argument!");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;
   Number := Positive'Value (Ada.Command_Line.Argument (1));
   Ada.Text_IO.Put ("Factors of" & Positive'Image (Number) & ": ");
   loop
      if Number mod Test_Nr = 0 then
         Ada.Text_IO.Put (Positive'Image (Test_Nr) & ",");
      end if;
      exit when Test_Nr ** 2 >= Number;
      Test_Nr := Test_Nr + 1;
   end loop;
   Ada.Text_IO.Put_Line (Positive'Image (Number) & ".");
end Factors;
Task: Factors of an integer

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

typedef struct {
    int *list;
    short count; 
} Factors;

void xferFactors( Factors *fctrs, int *flist, int flix ) 
{
    int ix, ij;
    int newSize = fctrs->count + flix;
    if (newSize > flix)  {
        fctrs->list = realloc( fctrs->list, newSize * sizeof(int));
    }
    else {
        fctrs->list = malloc(  newSize * sizeof(int));
    }
    for (ij=0,ix=fctrs->count; ix<newSize; ij++,ix++) {
        fctrs->list[ix] = flist[ij];
    }
    fctrs->count = newSize;
}

Factors *factor( int num, Factors *fctrs)
{
    int flist[301], flix;
    int dvsr;
    flix = 0;
    fctrs->count = 0;
    free(fctrs->list);
    fctrs->list = NULL;
    for (dvsr=1; dvsr*dvsr < num; dvsr++) {
        if (num % dvsr != 0) continue;
        if ( flix == 300) {
            xferFactors( fctrs, flist, flix );
            flix = 0;
        }
        flist[flix++] = dvsr;
        flist[flix++] = num/dvsr;
    }
    if (dvsr*dvsr == num) 
        flist[flix++] = dvsr;
    if (flix > 0)
        xferFactors( fctrs, flist, flix );

    return fctrs;
}
        
int main(int argc, char*argv[])
{
    int nums2factor[] = { 2059, 223092870, 3135, 45 };
    Factors ftors = { NULL, 0};
    char sep;
    int i,j;

    for (i=0; i<4; i++) {
        factor( nums2factor[i], &ftors );
        printf("\nfactors of %d are:\n  ", nums2factor[i]);
        sep = ' ';
        for (j=0; j<ftors.count; j++) {
            printf("%c %d", sep, ftors.list[j]);
            sep = ',';
        }
        printf("\n");
    }
    return 0;
}











Ada: with Ada.Text_IO;
with Ada.Command_Line;
procedure Factors is
   Number  : Positive;
   Test_Nr : Positive := 1;
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put (Ada.Text_IO.Standard_Error, "Missing argument!");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;
   Number := Positive'Value (Ada.Command_Line.Argument (1));
   Ada.Text_IO.Put ("Factors of" & Positive'Image (Number) & ": ");
   loop
      if Number mod Test_Nr = 0 then
         Ada.Text_IO.Put (Positive'Image (Test_Nr) & ",");
      end if;
      exit when Test_Nr ** 2 >= Number;
      Test_Nr := Test_Nr + 1;
   end loop;
   Ada.Text_IO.Put_Line (Positive'Image (Number) & ".");
end Factors;
Task: Factors of an integer


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

std::vector<int> GenerateFactors(int n) {
    std::vector<int> factors = { 1, n };
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            factors.push_back(i);
            if (i * i != n)
                factors.push_back(n / i);
        }
    }

    std::sort(factors.begin(), factors.end());
    return factors;
}

int main() {
    const int SampleNumbers[] = { 3135, 45, 60, 81 };

    for (size_t i = 0; i < sizeof(SampleNumbers) / sizeof(int); ++i) {
        std::vector<int> factors = GenerateFactors(SampleNumbers[i]);
        std::cout << "Factors of ";
        std::cout.width(4);
        std::cout << SampleNumbers[i] << " are: ";
        std::copy(factors.begin(), factors.end(), std::ostream_iterator<int>(std::cout, " "));
        std::cout << std::endl;
    }

    return EXIT_SUCCESS;
}










Ada: with Ada.Text_IO;
with Ada.Command_Line;
procedure Factors is
   Number  : Positive;
   Test_Nr : Positive := 1;
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put (Ada.Text_IO.Standard_Error, "Missing argument!");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;
   Number := Positive'Value (Ada.Command_Line.Argument (1));
   Ada.Text_IO.Put ("Factors of" & Positive'Image (Number) & ": ");
   loop
      if Number mod Test_Nr = 0 then
         Ada.Text_IO.Put (Positive'Image (Test_Nr) & ",");
      end if;
      exit when Test_Nr ** 2 >= Number;
      Test_Nr := Test_Nr + 1;
   end loop;
   Ada.Text_IO.Put_Line (Positive'Image (Number) & ".");
end Factors;
Task: Factors of an integer




Go: package main

import "fmt"

func main() {
    printFactors(-1)
    printFactors(0)
    printFactors(1)
    printFactors(2)
    printFactors(3)
    printFactors(53)
    printFactors(45)
    printFactors(64)
    printFactors(600851475143)
    printFactors(999999999999999989)
}

func printFactors(nr int64) {
    if nr < 1 {
        fmt.Println("\nFactors of", nr, "not computed")
        return
    }
    fmt.Printf("\nFactors of %d: ", nr)
    fs := make([]int64, 1)
    fs[0] = 1
    apf := func(p int64, e int) {
        n := len(fs)
        for i, pp := 0, p; i < e; i, pp = i+1, pp*p {
            for j := 0; j < n; j++ {
                fs = append(fs, fs[j]*pp)
            }
        }
    }
    e := 0
    for ; nr & 1 == 0; e++ {
        nr >>= 1
    }
    apf(2, e)
    for d := int64(3); nr > 1; d += 2 {
        if d*d > nr {
            d = nr
        }
        for e = 0; nr%d == 0; e++ {
            nr /= d
        }
        if e > 0 {
            apf(d, e)
        }
    }
    fmt.Println(fs)
    fmt.Println("Number of factors =", len(fs))
}








Ada: with Ada.Text_IO;
with Ada.Command_Line;
procedure Factors is
   Number  : Positive;
   Test_Nr : Positive := 1;
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put (Ada.Text_IO.Standard_Error, "Missing argument!");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;
   Number := Positive'Value (Ada.Command_Line.Argument (1));
   Ada.Text_IO.Put ("Factors of" & Positive'Image (Number) & ": ");
   loop
      if Number mod Test_Nr = 0 then
         Ada.Text_IO.Put (Positive'Image (Test_Nr) & ",");
      end if;
      exit when Test_Nr ** 2 >= Number;
      Test_Nr := Test_Nr + 1;
   end loop;
   Ada.Text_IO.Put_Line (Positive'Image (Number) & ".");
end Factors;
Task: Factors of an integer





Java: public static TreeSet<Long> factors(long n)
{
 TreeSet<Long> factors = new TreeSet<Long>();
 factors.add(n);
 factors.add(1L);
 for(long test = n - 1; test >= Math.sqrt(n); test--)
  if(n % test == 0)
  {
   factors.add(test);
   factors.add(n / test);
  }
 return factors;
}







Ada: with Ada.Text_IO;
with Ada.Command_Line;
procedure Factors is
   Number  : Positive;
   Test_Nr : Positive := 1;
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put (Ada.Text_IO.Standard_Error, "Missing argument!");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;
   Number := Positive'Value (Ada.Command_Line.Argument (1));
   Ada.Text_IO.Put ("Factors of" & Positive'Image (Number) & ": ");
   loop
      if Number mod Test_Nr = 0 then
         Ada.Text_IO.Put (Positive'Image (Test_Nr) & ",");
      end if;
      exit when Test_Nr ** 2 >= Number;
      Test_Nr := Test_Nr + 1;
   end loop;
   Ada.Text_IO.Put_Line (Positive'Image (Number) & ".");
end Factors;
Task: Factors of an integer







Python: >>> def factors(n):
      return [i for i in range(1, n + 1) if not n%i]





Ada: with Ada.Text_IO;
with Ada.Command_Line;
procedure Factors is
   Number  : Positive;
   Test_Nr : Positive := 1;
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put (Ada.Text_IO.Standard_Error, "Missing argument!");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;
   Number := Positive'Value (Ada.Command_Line.Argument (1));
   Ada.Text_IO.Put ("Factors of" & Positive'Image (Number) & ": ");
   loop
      if Number mod Test_Nr = 0 then
         Ada.Text_IO.Put (Positive'Image (Test_Nr) & ",");
      end if;
      exit when Test_Nr ** 2 >= Number;
      Test_Nr := Test_Nr + 1;
   end loop;
   Ada.Text_IO.Put_Line (Positive'Image (Number) & ".");
end Factors;
Task: Factors of an integer








VB: Function factors(num As UInt64) As UInt64()
  
  Dim result() As UInt64
  Dim iFactor As UInt64 = 1
  While iFactor <= num/2 
    If num Mod iFactor = 0 Then
      result.Append(iFactor)
    End If
    iFactor = iFactor + 1
  Wend
  result.Append(num) 
  Return result
End Function




Ada: with Ada.Text_IO;
with Ada.Command_Line;
procedure Factors is
   Number  : Positive;
   Test_Nr : Positive := 1;
begin
   if Ada.Command_Line.Argument_Count /= 1 then
      Ada.Text_IO.Put (Ada.Text_IO.Standard_Error, "Missing argument!");
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
      return;
   end if;
   Number := Positive'Value (Ada.Command_Line.Argument (1));
   Ada.Text_IO.Put ("Factors of" & Positive'Image (Number) & ": ");
   loop
      if Number mod Test_Nr = 0 then
         Ada.Text_IO.Put (Positive'Image (Test_Nr) & ",");
      end if;
      exit when Test_Nr ** 2 >= Number;
      Test_Nr := Test_Nr + 1;
   end loop;
   Ada.Text_IO.Put_Line (Positive'Image (Number) & ".");
end Factors;
Task: Factors of an integer

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

typedef struct {
    int *list;
    short count; 
} Factors;

void xferFactors( Factors *fctrs, int *flist, int flix ) 
{
    int ix, ij;
    int newSize = fctrs->count + flix;
    if (newSize > flix)  {
        fctrs->list = realloc( fctrs->list, newSize * sizeof(int));
    }
    else {
        fctrs->list = malloc(  newSize * sizeof(int));
    }
    for (ij=0,ix=fctrs->count; ix<newSize; ij++,ix++) {
        fctrs->list[ix] = flist[ij];
    }
    fctrs->count = newSize;
}

Factors *factor( int num, Factors *fctrs)
{
    int flist[301], flix;
    int dvsr;
    flix = 0;
    fctrs->count = 0;
    free(fctrs->list);
    fctrs->list = NULL;
    for (dvsr=1; dvsr*dvsr < num; dvsr++) {
        if (num % dvsr != 0) continue;
        if ( flix == 300) {
            xferFactors( fctrs, flist, flix );
            flix = 0;
        }
        flist[flix++] = dvsr;
        flist[flix++] = num/dvsr;
    }
    if (dvsr*dvsr == num) 
        flist[flix++] = dvsr;
    if (flix > 0)
        xferFactors( fctrs, flist, flix );

    return fctrs;
}
        
int main(int argc, char*argv[])
{
    int nums2factor[] = { 2059, 223092870, 3135, 45 };
    Factors ftors = { NULL, 0};
    char sep;
    int i,j;

    for (i=0; i<4; i++) {
        factor( nums2factor[i], &ftors );
        printf("\nfactors of %d are:\n  ", nums2factor[i]);
        sep = ' ';
        for (j=0; j<ftors.count; j++) {
            printf("%c %d", sep, ftors.list[j]);
            sep = ',';
        }
        printf("\n");
    }
    return 0;
}
Task: Factors of an integer



C#: static void Main (string[] args) {
    do {
        Console.WriteLine ("Number:");
        Int64 p = 0;
        do {
            try {
                p = Convert.ToInt64 (Console.ReadLine ());
                break;
            } catch (Exception) { }

        } while (true);

        Console.WriteLine ("For 1 through " + ((int) Math.Sqrt (p)).ToString () + "");
        for (int x = 1; x <= (int) Math.Sqrt (p); x++) {
            if (p % x == 0)
                Console.WriteLine ("Found: " + x.ToString () + ". " + p.ToString () + " / " + x.ToString () + " = " + (p / x).ToString ());
        }

        Console.WriteLine ("Done.");
    } while (true);
}
Task: Factors of an integer


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

std::vector<int> GenerateFactors(int n) {
    std::vector<int> factors = { 1, n };
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            factors.push_back(i);
            if (i * i != n)
                factors.push_back(n / i);
        }
    }

    std::sort(factors.begin(), factors.end());
    return factors;
}

int main() {
    const int SampleNumbers[] = { 3135, 45, 60, 81 };

    for (size_t i = 0; i < sizeof(SampleNumbers) / sizeof(int); ++i) {
        std::vector<int> factors = GenerateFactors(SampleNumbers[i]);
        std::cout << "Factors of ";
        std::cout.width(4);
        std::cout << SampleNumbers[i] << " are: ";
        std::copy(factors.begin(), factors.end(), std::ostream_iterator<int>(std::cout, " "));
        std::cout << std::endl;
    }

    return EXIT_SUCCESS;
}
Task: Factors of an integer





Java: public static TreeSet<Long> factors(long n)
{
 TreeSet<Long> factors = new TreeSet<Long>();
 factors.add(n);
 factors.add(1L);
 for(long test = n - 1; test >= Math.sqrt(n); test--)
  if(n % test == 0)
  {
   factors.add(test);
   factors.add(n / test);
  }
 return factors;
}
Task: Factors of an integer







Python: >>> def factors(n):
      return [i for i in range(1, n + 1) if not n%i]
Task: Factors of an integer








VB: Function factors(num As UInt64) As UInt64()
  
  Dim result() As UInt64
  Dim iFactor As UInt64 = 1
  While iFactor <= num/2 
    If num Mod iFactor = 0 Then
      result.Append(iFactor)
    End If
    iFactor = iFactor + 1
  Wend
  result.Append(num) 
  Return result
End Function
Task: Factors of an integer




Go: package main

import "fmt"

func main() {
    printFactors(-1)
    printFactors(0)
    printFactors(1)
    printFactors(2)
    printFactors(3)
    printFactors(53)
    printFactors(45)
    printFactors(64)
    printFactors(600851475143)
    printFactors(999999999999999989)
}

func printFactors(nr int64) {
    if nr < 1 {
        fmt.Println("\nFactors of", nr, "not computed")
        return
    }
    fmt.Printf("\nFactors of %d: ", nr)
    fs := make([]int64, 1)
    fs[0] = 1
    apf := func(p int64, e int) {
        n := len(fs)
        for i, pp := 0, p; i < e; i, pp = i+1, pp*p {
            for j := 0; j < n; j++ {
                fs = append(fs, fs[j]*pp)
            }
        }
    }
    e := 0
    for ; nr & 1 == 0; e++ {
        nr >>= 1
    }
    apf(2, e)
    for d := int64(3); nr > 1; d += 2 {
        if d*d > nr {
            d = nr
        }
        for e = 0; nr%d == 0; e++ {
            nr /= d
        }
        if e > 0 {
            apf(d, e)
        }
    }
    fmt.Println(fs)
    fmt.Println("Number of factors =", len(fs))
}
Task: Factors of an integer



C#: static void Main (string[] args) {
    do {
        Console.WriteLine ("Number:");
        Int64 p = 0;
        do {
            try {
                p = Convert.ToInt64 (Console.ReadLine ());
                break;
            } catch (Exception) { }

        } while (true);

        Console.WriteLine ("For 1 through " + ((int) Math.Sqrt (p)).ToString () + "");
        for (int x = 1; x <= (int) Math.Sqrt (p); x++) {
            if (p % x == 0)
                Console.WriteLine ("Found: " + x.ToString () + ". " + p.ToString () + " / " + x.ToString () + " = " + (p / x).ToString ());
        }

        Console.WriteLine ("Done.");
    } while (true);
}








Fortran: program Factors
  implicit none
  integer :: i, number
  
  write(*,*) "Enter a number between 1 and 2147483647"
  read*, number

  do i = 1, int(sqrt(real(number))) - 1
    if (mod(number, i) == 0) write (*,*) i, number/i
  end do
  
  
  i = int(sqrt(real(number))) 
  if (i*i == number) then
     write (*,*) i
  else if (mod(number, i) == 0) then
     write (*,*) i, number/i
  end if
    
end program
Task: Factors of an integer


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

std::vector<int> GenerateFactors(int n) {
    std::vector<int> factors = { 1, n };
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            factors.push_back(i);
            if (i * i != n)
                factors.push_back(n / i);
        }
    }

    std::sort(factors.begin(), factors.end());
    return factors;
}

int main() {
    const int SampleNumbers[] = { 3135, 45, 60, 81 };

    for (size_t i = 0; i < sizeof(SampleNumbers) / sizeof(int); ++i) {
        std::vector<int> factors = GenerateFactors(SampleNumbers[i]);
        std::cout << "Factors of ";
        std::cout.width(4);
        std::cout << SampleNumbers[i] << " are: ";
        std::copy(factors.begin(), factors.end(), std::ostream_iterator<int>(std::cout, " "));
        std::cout << std::endl;
    }

    return EXIT_SUCCESS;
}









Fortran: program Factors
  implicit none
  integer :: i, number
  
  write(*,*) "Enter a number between 1 and 2147483647"
  read*, number

  do i = 1, int(sqrt(real(number))) - 1
    if (mod(number, i) == 0) write (*,*) i, number/i
  end do
  
  
  i = int(sqrt(real(number))) 
  if (i*i == number) then
     write (*,*) i
  else if (mod(number, i) == 0) then
     write (*,*) i, number/i
  end if
    
end program