Alcuin’s Sequence

Alcuin sequence is the expansion of

This series has significant importance as

  • Alcuin Sequence a(n) is the number of triangles with integer sides and the perimeter of the triangle is n.
  • Alcuin Sequence a(n) is the number of triangles with distinct integer sides and the perimeter of the triangle is n+6.

The Alcuin sequence is as follows:



0, 0, 1, 0, 1, 1, 2, 1, 3, 2

Examples:

Input: n = 10
Output: 0, 0, 1, 0, 1, 
        1, 2, 1, 3, 2
Input: n = 15
Output:0, 0, 1, 0, 1, 
        1, 2, 1, 3, 2, 
        4, 3, 5, 4, 7, 

Approach:

  • Find the nth term of the Alcuin sequence using
    a(n) = round(n^2/12) – floor(n/4)*floor((n+2)/4)
  • Find out the ith term and display it.

Below is the implementation of the above approach:

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <bits/stdc++.h>
using namespace std;
  
// find the nth term  of
// Alcuin's sequence
int Alcuin(int n)
{
    double _n = n, ans;
  
    ans = round((_n * _n) / 12)
          - floor(_n / 4)
                * floor((_n + 2) / 4);
  
    // return the ans
    return ans;
}
  
// print first n terms of Alcuin number
void solve(int n)
{
    int i = 0;
  
    for (int i = 1; i <= n; i++) {
  
        // display the number
        cout << Alcuin(i) << ", ";
    }
}
  
// Driver code
int main()
{
    int n = 15;
    solve(n);
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program for Alcuin's Sequence
import java.util.*;
  
class GFG 
{
  
// find the nth term of
// Alcuin's sequence
static int Alcuin(int n)
{
    double _n = n, ans;
  
    ans = Math.round((_n * _n) / 12) - 
          Math.floor(_n / 4) * 
          Math.floor((_n + 2) / 4);
  
    // return the ans
    return (int) ans;
}
  
// print first n terms of Alcuin number
static void solve(int n)
{
    int i = 0;
  
    for (i = 1; i <= n; i++) 
    {
  
        // display the number
        System.out.print(Alcuin(i) + ", ");
    }
}
  
// Driver code
public static void main(String[] args) 
{
    int n = 15;
    solve(n);
}
}
  
// This code is contributed by Princi Singh

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program for Alcuin’s Sequence
from math import ceil, floor
  
# find the nth term of
# Alcuin's sequence
def Alcuin(n):
  
    _n = n
    ans = 0
  
    ans = (round((_n * _n) / 12) - 
            floor(_n / 4) * 
            floor((_n + 2) / 4))
  
    # return the ans
    return ans
  
# print first n terms of Alcuin number
def solve(n):
  
    for i in range(1, n + 1):
  
        # display the number
        print(Alcuin(i), end = ", ")
      
# Driver code
n = 15
solve(n)
  
# This code is contributed by Mohit Kumar

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for Alcuin's Sequence
using System;
      
class GFG 
{
  
    // find the nth term of
    // Alcuin's sequence
    static int Alcuin(int n)
    {
        double _n = n, ans;
  
        ans = Math.Round((_n * _n) / 12) - 
              Math.Floor(_n / 4) * 
              Math.Floor((_n + 2) / 4);
  
        // return the ans
        return (int) ans;
    }
  
    // print first n terms of Alcuin number
    static void solve(int n)
    {
        int i = 0;
  
        for (i = 1; i <= n; i++) 
        {
  
            // display the number
            Console.Write(Alcuin(i) + ", ");
        }
    }
  
    // Driver code
    public static void Main(String[] args) 
    {
        int n = 15;
        solve(n);
    }
}
  
// This code is contributed by Rajput-Ji

chevron_right



Output:

0, 0, 1, 0, 1, 1, 2, 1, 3, 2, 4, 3, 5, 4, 7, 

Reference: https://en.wikipedia.org/wiki/Alcuin%27s_sequence



My Personal Notes arrow_drop_up

Second year Department of Information Technology Jadavpur University

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.





Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.