File: math_primitive_root_example.c

package info (click to toggle)
liquid-dsp 1.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,216 kB
  • sloc: ansic: 115,859; sh: 3,513; makefile: 1,350; python: 274; asm: 11
file content (29 lines) | stat: -rw-r--r-- 568 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
// math_primitive_root_example.c
//
// Demonstrates computing primitive root of a number using modular
// arithmetic.
//

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

#include "liquid.h"

int main(int argc, char*argv[])
{
    // maximum number
    unsigned int n = 140;
    unsigned int i;

    printf("primitive roots of prime numbers up to %u:\n", n);
    for (i=3; i<=n; i++) {
        if (!liquid_is_prime(i))
            continue;
        
        unsigned int root = liquid_primitive_root_prime(i);
        printf("  %4u : %4u\n", i, root);
    }

    return 0;
}