examples/Integer/primitiveroot.C

NO DOC.

NO DOC

// Copyright(c)'1994-2009 by The Givaro group
// This file is part of Givaro.
// Givaro is governed by the CeCILL-B license under French law
// and abiding by the rules of distribution of free software.
// see the COPYRIGHT file for more details.
#include <iostream>
#define GIVARO_LENSTRA
#include <givaro/givintnumtheo.h>
#include <givaro/givtimer.h>
#ifndef TIMING
#define TIMING 1
#endif
using namespace Givaro;
int main(int argc, char** argv)
{
IntNumTheoDom<> IP;
#ifndef __GIVARO_GMP_NO_CXX
IP.seeding();
#endif
IntNumTheoDom<>::Element a,pr;
if (argc > 1) a = IntNumTheoDom<>::Element(argv[1]); else std::cin >> a;
uint64_t runs(0);
Timer tim; tim.clear();
if (IP.isprime(a)) {
Integer phin; IP.sub(phin,a,IP.one);
std::vector<Integer> Lf;
IP.write(std::cout << "Totient : ", Lf,phin) << std::endl;
tim.start();
for(uint64_t i = 0; i < TIMING; ++i)
IP.prim_root_of_prime(pr, a);
tim.stop();
IP.write( std::cout << "Deterministic : ", pr ) << std::endl;
std::cerr << tim << std::endl;
}
tim.start();
for(uint64_t i = 0; i < TIMING; ++i)
IP.prim_root(pr, runs, a);
tim.stop();
IP.write( std::cout << "Random : ", pr ) << std::endl;
std::cerr << tim << " (" << runs << " runs)" << std::endl;
tim.start();
for(uint64_t i = 0; i < TIMING; ++i)
IP.lowest_prim_root(pr, a);
tim.stop();
IP.write( std::cout << "Lowest : ", pr ) << std::endl;
std::cerr << tim << std::endl;
return 0;
}
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
Givaro::IntNumTheoDom
Num theory Domain.
Definition givintnumtheo.h:33
Givaro::Integer
This is the Integer class.
Definition gmp++_int.h:160
Givaro::Integer::sub
static giv_all_inlined Integer & sub(Integer &res, const Integer &n1, const Integer &n2)
Substraction res=n1-n2.
Definition gmp++_int_sub.C:58
Givaro::Timer
Timer.
Definition givtimer.h:129
Givaro::Timer::start
void start()
Start timer.
Definition givtimer.C:164
Givaro::Timer::stop
void stop()
Stop timer.
Definition givtimer.C:172
Givaro::Timer::clear
void clear()
Clear timer.
Definition givtimer.C:155
Givaro
Namespace in which the whole Givaro library resides.
Definition all_field.C:23