mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Miscellaneous Math

Reply
 
Thread Tools
Old 2018-04-15, 19:16   #34
Godzilla
 
Godzilla's Avatar
 
May 2016

2·34 Posts
Default

@VBcurtis unfortunately it comes up to the number 31 with the C ++ code I have to try - build a program with the GMP library.
@Scienceman88 what you say is not correct, try my c ++ program
@Batalov

Code C++

Code:
#include<iostream>
using namespace std;
#include<cmath>

int main()

{

	long double a = 0;
	long double p= 1;
	//long long int equ = aa*((1-2^-p)*(2^p-1));
	long double div = 0;
	long int mod = 0;
	long double mul = 0;
    long int i = 1;
	long double aa = 0.5;
	long double equ = 0 ;

	while (p <=341)
	{

		long double equTwo= 1-(1/(pow(2,p)));
		equ = aa*(equTwo*(pow(2,p)-1));
		mod= equ;
		//div = equ / i;
		//mul = div * i;
		//mod = equ-mul;
		mod = mod%i;

		cout<<"equ= "<<equ<<"p= "<<p<<"mod = "<<mod<<"\n\n";

		p++;
		i++;
	}
	cin>>i;
}

Last fiddled with by Godzilla on 2018-04-15 at 19:18
Godzilla is offline   Reply With Quote
Old 2018-04-15, 19:27   #35
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Quote:
Originally Posted by Godzilla View Post
@Scienceman88 what you say is not correct, try my c ++ program
I don't have to, I know that 0.5 only makes sense modularly as (1 mod p)/(2 mod p). Knowing 2³=8= 2 mod 3 allows that 2^-p to be simplified to (1 mod 3)/(2 mod 3) for p=3. Furthermore if p is prime it is known that 2^p-1 is congruent to 1 mod p.

Last fiddled with by science_man_88 on 2018-04-15 at 19:36
science_man_88 is offline   Reply With Quote
Old 2018-04-15, 19:37   #36
Batalov
 
Batalov's Avatar
 
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

250516 Posts
Default

Quote:
Originally Posted by Godzilla View Post
@Batalov

Code C++

Code:
#include<iostream>
using namespace std;
#include<cmath>

int main()

{

    long double a = 0;
    long double p= 1;
    //long long int equ = aa*((1-2^-p)*(2^p-1));
    long double div = 0;
    long int mod = 0;
    long double mul = 0;
    long int i = 1;
    long double aa = 0.5;
    long double equ = 0 ;

    while (p <=341)
    {

        long double equTwo= 1-(1/(pow(2,p)));
cout << "Let's see if I have enough precision... " << equTwo << " for p=" << p <<"\n";
        equ = aa*(equTwo*(pow(2,p)-1));
        mod= equ;
        //div = equ / i;
        //mul = div * i;
        //mod = equ-mul;
        mod = mod%i;

        cout<<"equ= "<<equ<<"p= "<<p<<"mod = "<<mod<<"\n\n";

        p++;
        i++;
    }
    cin>>i;
}
The following is true in any language, including English:
merely knowing the language doesn't mean that you are able to say something meaningful.
Batalov is offline   Reply With Quote
Old 2018-04-16, 04:12   #37
Godzilla
 
Godzilla's Avatar
 
May 2016

2×34 Posts
Default

Output with zero with this program up to 31 is :

Code:
equ= 0.25p= 1mod = 0     fails

equ= 1.125p= 2mod = 1   fails

equ= 3.0625p= 3mod = 0

equ= 7.03125p= 4mod = 3

equ= 15.0156p= 5mod = 0

equ= 31.0078p= 6mod = 1

equ= 63.0039p= 7mod = 0

equ= 127.002p= 8mod = 7

equ= 255.001p= 9mod = 3

equ= 511p= 10mod = 1

equ= 1023p= 11mod = 0

equ= 2047p= 12mod = 7

equ= 4095p= 13mod = 0

equ= 8191p= 14mod = 1

equ= 16383p= 15mod = 3

equ= 32767p= 16mod = 15

equ= 65535p= 17mod = 0

equ= 131071p= 18mod = 13

equ= 262143p= 19mod = 0

equ= 524287p= 20mod = 7

equ= 1.04858e+006p= 21mod = 3

equ= 2.09715e+006p= 22mod = 1

equ= 4.1943e+006p= 23mod = 0

equ= 8.38861e+006p= 24mod = 7

equ= 1.67772e+007p= 25mod = 15

equ= 3.35544e+007p= 26mod = 1

equ= 6.71089e+007p= 27mod = 12

equ= 1.34218e+008p= 28mod = 7

equ= 2.68435e+008p= 29mod = 0

equ= 5.36871e+008p= 30mod = 1

equ= 1.07374e+009p= 31mod = 0
over the number 31 mod is negative with this c++ program , but for example i had test with the number 341 with another program and fails because is equal to 0 , (i know that fails at the moment for 1 , 2 and 341 and not other).

this is the negative output over number 31

Code:
equ= 2.14748e+009p= 32mod = 31

equ= 4.29497e+009p= 33mod = -2

equ= 8.58993e+009p= 34mod = -26

equ= 1.71799e+010p= 35mod = -23

equ= 3.43597e+010p= 36mod = -20

equ= 6.87195e+010p= 37mod = -22

equ= 1.37439e+011p= 38mod = -22

equ= 2.74878e+011p= 39mod = -11

equ= 5.49756e+011p= 40mod = -8

equ= 1.09951e+012p= 41mod = -39

equ= 2.19902e+012p= 42mod = -2

equ= 4.39805e+012p= 43mod = -8

equ= 8.79609e+012p= 44mod = -24

equ= 1.75922e+013p= 45mod = -38

equ= 3.51844e+013p= 46mod = -6

equ= 7.03687e+013p= 47mod = -21

equ= 1.40737e+014p= 48mod = -32

equ= 2.81475e+014p= 49mod = -44

equ= 5.6295e+014p= 50mod = -48

equ= 1.1259e+015p= 51mod = -26

equ= 2.2518e+015p= 52mod = -24

equ= 4.5036e+015p= 53mod = -21

equ= 9.0072e+015p= 54mod = -38

equ= 1.80144e+016p= 55mod = -13

equ= 3.60288e+016p= 56mod = -16

equ= 7.20576e+016p= 57mod = -41

equ= 1.44115e+017p= 58mod = -8

equ= 2.8823e+017p= 59mod = -55

equ= 5.76461e+017p= 60mod = -8

equ= 1.15292e+018p= 61mod = -59

equ= 2.30584e+018p= 62mod = -2

equ= 4.61169e+018p= 63mod = -2

equ= 9.22337e+018p= 64mod = 0

equ= 1.84467e+019p= 65mod = -63

equ= 3.68935e+019p= 66mod = -2

equ= 7.3787e+019p= 67mod = -50

equ= 1.47574e+020p= 68mod = -60

equ= 2.95148e+020p= 69mod = -29

equ= 5.90296e+020p= 70mod = -58

equ= 1.18059e+021p= 71mod = -40

equ= 2.36118e+021p= 72mod = -56

equ= 4.72237e+021p= 73mod = -16

equ= 9.44473e+021p= 74mod = -22

equ= 1.88895e+022p= 75mod = -23

equ= 3.77789e+022p= 76mod = -60

equ= 7.55579e+022p= 77mod = -2

equ= 1.51116e+023p= 78mod = -50

equ= 3.02231e+023p= 79mod = -25

equ= 6.04463e+023p= 80mod = -48

equ= 1.20893e+024p= 81mod = -65

equ= 2.41785e+024p= 82mod = -80

equ= 4.8357e+024p= 83mod = -80

equ= 9.67141e+024p= 84mod = -44

equ= 1.93428e+025p= 85mod = -43

equ= 3.86856e+025p= 86mod = -8

equ= 7.73713e+025p= 87mod = -8

equ= 1.54743e+026p= 88mod = -24

equ= 3.09485e+026p= 89mod = -67

equ= 6.1897e+026p= 90mod = -38

equ= 1.23794e+027p= 91mod = -37

equ= 2.47588e+027p= 92mod = -52

equ= 4.95176e+027p= 93mod = -2

equ= 9.90352e+027p= 94mod = -68

equ= 1.9807e+028p= 95mod = -3

equ= 3.96141e+028p= 96mod = -32

equ= 7.92282e+028p= 97mod = -66

equ= 1.58456e+029p= 98mod = -44

equ= 3.16913e+029p= 99mod = -2

equ= 6.33825e+029p= 100mod = -48

equ= 1.26765e+030p= 101mod = -34

equ= 2.5353e+030p= 102mod = -26

equ= 5.0706e+030p= 103mod = -83

equ= 1.01412e+031p= 104mod = -24

equ= 2.02824e+031p= 105mod = -23

equ= 4.05648e+031p= 106mod = -74

equ= 8.11296e+031p= 107mod = -68

equ= 1.62259e+032p= 108mod = -92

equ= 3.24519e+032p= 109mod = -92

equ= 6.49037e+032p= 110mod = -68

equ= 1.29807e+033p= 111mod = -59

equ= 2.59615e+033p= 112mod = -16

equ= 5.1923e+033p= 113mod = -8

equ= 1.03846e+034p= 114mod = -98

equ= 2.07692e+034p= 115mod = -98

equ= 4.15384e+034p= 116mod = -8

equ= 8.30767e+034p= 117mod = -11

equ= 1.66153e+035p= 118mod = -114

equ= 3.32307e+035p= 119mod = -9

equ= 6.64614e+035p= 120mod = -8

equ= 1.32923e+036p= 121mod = -90

equ= 2.65846e+036p= 122mod = -120

equ= 5.31691e+036p= 123mod = -80

equ= 1.06338e+037p= 124mod = -64

equ= 2.12676e+037p= 125mod = -23

equ= 4.25353e+037p= 126mod = -2

equ= 8.50706e+037p= 127mod = -8

equ= 1.70141e+038p= 128mod = 0

equ= 3.40282e+038p= 129mod = -8

equ= 6.80565e+038p= 130mod = -128

equ= 1.36113e+039p= 131mod = -124

equ= 2.72226e+039p= 132mod = -68

equ= 5.44452e+039p= 133mod = -79

equ= 1.0889e+040p= 134mod = -50

equ= 2.17781e+040p= 135mod = -38

equ= 4.35561e+040p= 136mod = -128

equ= 8.71123e+040p= 137mod = -17

equ= 1.74225e+041p= 138mod = -98

equ= 3.48449e+041p= 139mod = -90

equ= 6.96898e+041p= 140mod = -128

equ= 1.3938e+042p= 141mod = -68

equ= 2.78759e+042p= 142mod = -40

equ= 5.57519e+042p= 143mod = -24

equ= 1.11504e+043p= 144mod = -128

equ= 2.23007e+043p= 145mod = -8

equ= 4.46015e+043p= 146mod = -16

equ= 8.9203e+043p= 147mod = -44

equ= 1.78406e+044p= 148mod = -96

equ= 3.56812e+044p= 149mod = -139

equ= 7.13624e+044p= 150mod = -98

equ= 1.42725e+045p= 151mod = -2

equ= 2.8545e+045p= 152mod = -136

equ= 5.70899e+045p= 153mod = -128

equ= 1.1418e+046p= 154mod = -2

equ= 2.2836e+046p= 155mod = -33

equ= 4.56719e+046p= 156mod = -128

equ= 9.13439e+046p= 157mod = -125

equ= 1.82688e+047p= 158mod = -104

equ= 3.65375e+047p= 159mod = -74

equ= 7.30751e+047p= 160mod = -128

equ= 1.4615e+048p= 161mod = -121

equ= 2.923e+048p= 162mod = -146

equ= 5.84601e+048p= 163mod = -50

equ= 1.1692e+049p= 164mod = -80

equ= 2.3384e+049p= 165mod = -68

equ= 4.67681e+049p= 166mod = -80

equ= 9.35361e+049p= 167mod = -87

equ= 1.87072e+050p= 168mod = -128

equ= 3.74144e+050p= 169mod = -141

equ= 7.48289e+050p= 170mod = -128

equ= 1.49658e+051p= 171mod = -155

equ= 2.99316e+051p= 172mod = -8

equ= 5.98631e+051p= 173mod = -48

equ= 1.19726e+052p= 174mod = -8

equ= 2.39452e+052p= 175mod = -23

equ= 4.78905e+052p= 176mod = -112

equ= 9.5781e+052p= 177mod = -173

equ= 1.91562e+053p= 178mod = -156

equ= 3.83124e+053p= 179mod = -63

equ= 7.66248e+053p= 180mod = -128

equ= 1.5325e+054p= 181mod = -98

equ= 3.06499e+054p= 182mod = -128

equ= 6.12998e+054p= 183mod = -59

equ= 1.226e+055p= 184mod = -144

equ= 2.45199e+055p= 185mod = -133

equ= 4.90399e+055p= 186mod = -2

equ= 9.80797e+055p= 187mod = -145

equ= 1.96159e+056p= 188mod = -68

equ= 3.92319e+056p= 189mod = -65

equ= 7.84638e+056p= 190mod = -98

equ= 1.56928e+057p= 191mod = -169

equ= 3.13855e+057p= 192mod = -128

equ= 6.2771e+057p= 193mod = -54

equ= 1.25542e+058p= 194mod = -66

equ= 2.51084e+058p= 195mod = -128

equ= 5.02168e+058p= 196mod = -44

equ= 1.00434e+059p= 197mod = -44

equ= 2.00867e+059p= 198mod = -2

equ= 4.01735e+059p= 199mod = -23

equ= 8.03469e+059p= 200mod = -48

equ= 1.60694e+060p= 201mod = -50

equ= 3.21388e+060p= 202mod = -34

equ= 6.42775e+060p= 203mod = -37

equ= 1.28555e+061p= 204mod = -128

equ= 2.5711e+061p= 205mod = -203

equ= 5.1422e+061p= 206mod = -186

equ= 1.02844e+062p= 207mod = -29

equ= 2.05688e+062p= 208mod = -128

equ= 4.11376e+062p= 209mod = -79

equ= 8.22752e+062p= 210mod = -128

equ= 1.6455e+063p= 211mod = -131

equ= 3.29101e+063p= 212mod = -180

equ= 6.58202e+063p= 213mod = -182

equ= 1.3164e+064p= 214mod = -68

equ= 2.63281e+064p= 215mod = -8

equ= 5.26561e+064p= 216mod = -200

equ= 1.05312e+065p= 217mod = -2

equ= 2.10625e+065p= 218mod = -92

equ= 4.21249e+065p= 219mod = -89

equ= 8.42498e+065p= 220mod = -68

equ= 1.685e+066p= 221mod = -128

equ= 3.36999e+066p= 222mod = -170

equ= 6.73999e+066p= 223mod = -115

equ= 1.348e+067p= 224mod = -128

equ= 2.69599e+067p= 225mod = -173

equ= 5.39199e+067p= 226mod = -8

equ= 1.0784e+068p= 227mod = -88

equ= 2.1568e+068p= 228mod = -212

equ= 4.31359e+068p= 229mod = -195

equ= 8.62718e+068p= 230mod = -98

equ= 1.72544e+069p= 231mod = -2

equ= 3.45087e+069p= 232mod = -8

equ= 6.90175e+069p= 233mod = -4

equ= 1.38035e+070p= 234mod = -128

equ= 2.7607e+070p= 235mod = -68

equ= 5.5214e+070p= 236mod = -232

equ= 1.10428e+071p= 237mod = -104

equ= 2.20856e+071p= 238mod = -128

equ= 4.41712e+071p= 239mod = -55

equ= 8.83424e+071p= 240mod = -128

equ= 1.76685e+072p= 241mod = -128

equ= 3.53369e+072p= 242mod = -90

equ= 7.06739e+072p= 243mod = -65

equ= 1.41348e+073p= 244mod = -120

equ= 2.82696e+073p= 245mod = -93

equ= 5.65391e+073p= 246mod = -80

equ= 1.13078e+074p= 247mod = -193

equ= 2.26156e+074p= 248mod = -64

equ= 4.52313e+074p= 249mod = -80

equ= 9.04626e+074p= 250mod = -148

equ= 1.80925e+075p= 251mod = -187

equ= 3.6185e+075p= 252mod = -128

equ= 7.23701e+075p= 253mod = -167

equ= 1.4474e+076p= 254mod = -8

equ= 2.8948e+076p= 255mod = -128

equ= 5.7896e+076p= 256mod = 0

equ= 1.15792e+077p= 257mod = -129

equ= 2.31584e+077p= 258mod = -8

equ= 4.63168e+077p= 259mod = -170

equ= 9.26337e+077p= 260mod = -128

equ= 1.85267e+078p= 261mod = -182

equ= 3.70535e+078p= 262mod = -124

equ= 7.41069e+078p= 263mod = -17

equ= 1.48214e+079p= 264mod = -200

equ= 2.96428e+079p= 265mod = -233

equ= 5.92855e+079p= 266mod = -212

equ= 1.18571e+080p= 267mod = -245

equ= 2.37142e+080p= 268mod = -184

equ= 4.74284e+080p= 269mod = -158

equ= 9.48569e+080p= 270mod = -38

equ= 1.89714e+081p= 271mod = -245

equ= 3.79428e+081p= 272mod = -128

equ= 7.58855e+081p= 273mod = -128

equ= 1.51771e+082p= 274mod = -154

equ= 3.03542e+082p= 275mod = -123

equ= 6.07084e+082p= 276mod = -236

equ= 1.21417e+083p= 277mod = -152

equ= 2.42834e+083p= 278mod = -90

equ= 4.85667e+083p= 279mod = -2

equ= 9.71334e+083p= 280mod = -128

equ= 1.94267e+084p= 281mod = -158

equ= 3.88534e+084p= 282mod = -68

equ= 7.77068e+084p= 283mod = -125

equ= 1.55414e+085p= 284mod = -40

equ= 3.10827e+085p= 285mod = -98

equ= 6.21654e+085p= 286mod = -24

equ= 1.24331e+086p= 287mod = -121

equ= 2.48662e+086p= 288mod = -128

equ= 4.97323e+086p= 289mod = -77

equ= 9.94646e+086p= 290mod = -8

equ= 1.98929e+087p= 291mod = -260

equ= 3.97859e+087p= 292mod = -16

equ= 7.95717e+087p= 293mod = -213

equ= 1.59143e+088p= 294mod = -44

equ= 3.18287e+088p= 295mod = -173

equ= 6.36574e+088p= 296mod = -96

equ= 1.27315e+089p= 297mod = -200

equ= 2.54629e+089p= 298mod = -288

equ= 5.09259e+089p= 299mod = -167

equ= 1.01852e+090p= 300mod = -248

equ= 2.03704e+090p= 301mod = -51

equ= 4.07407e+090p= 302mod = -2

equ= 8.14814e+090p= 303mod = -236

equ= 1.62963e+091p= 304mod = -288

equ= 3.25926e+091p= 305mod = -303

equ= 6.51852e+091p= 306mod = -128

equ= 1.3037e+092p= 307mod = -228

equ= 2.60741e+092p= 308mod = -156

equ= 5.21481e+092p= 309mod = -83

equ= 1.04296e+093p= 310mod = -188

equ= 2.08592e+093p= 311mod = -36

equ= 4.17185e+093p= 312mod = -128

equ= 8.3437e+093p= 313mod = -38

equ= 1.66874e+094p= 314mod = -282

equ= 3.33748e+094p= 315mod = -128

equ= 6.67496e+094p= 316mod = -104

equ= 1.33499e+095p= 317mod = -116

equ= 2.66998e+095p= 318mod = -74

equ= 5.33997e+095p= 319mod = -211

equ= 1.06799e+096p= 320mod = -128

equ= 2.13599e+096p= 321mod = -68

equ= 4.27197e+096p= 322mod = -282

equ= 8.54395e+096p= 323mod = -60

equ= 1.70879e+097p= 324mod = -308

equ= 3.41758e+097p= 325mod = -323

equ= 6.83516e+097p= 326mod = -50

equ= 1.36703e+098p= 327mod = -92

equ= 2.73406e+098p= 328mod = -80

equ= 5.46813e+098p= 329mod = -303

equ= 1.09363e+099p= 330mod = -68

equ= 2.18725e+099p= 331mod = -2

equ= 4.3745e+099p= 332mod = -80

equ= 8.749e+099p= 333mod = -281

equ= 1.7498e+100p= 334mod = -254

equ= 3.4996e+100p= 335mod = -318

equ= 6.9992e+100p= 336mod = -128

equ= 1.39984e+101p= 337mod = -13

equ= 2.79968e+101p= 338mod = -310

equ= 5.59936e+101p= 339mod = -8

equ= 1.11987e+102p= 340mod = -128

equ= 2.23974e+102p= 341mod = -2

Last fiddled with by Godzilla on 2018-04-16 at 04:13
Godzilla is offline   Reply With Quote
Old 2018-04-16, 12:21   #38
Dr Sardonicus
 
Dr Sardonicus's Avatar
 
Feb 2017
Nowhere

4,643 Posts
Default

Quote:
Originally Posted by Batalov View Post
The following is true in any language, including English:
merely knowing the language doesn't mean that you are able to say something meaningful.
Fascinating. Thanks, all, for posting the OP's latest nonsensical claim and code, I wouldn't have read it otherwise


I'm hazy on the nomenclature for C numeric types (though, I suspect, not as hazy as the OP), but a "C long integer" is a twos complement integer of -- what? 8 bytes? and a "long double" is (I think) a limited-precision real number. (The old "double precision" numbers I'm familiar with had a sign bit, 11 bits for a "biased" exponent, and 52 bits of mantissa, with an extra assumed first bit of 1.) This, suggests, to my febrile imagination, the notion of rounding error.

I know, this is irrelevant for modulo arithmetic, which is exact, but it looks to me as though the OP has no idea of how modulo arithmetic actually works.

Anyhow, with the notion of rounding error in mind, I just multiply everything out and see what I can see.

(1/2)*(2p - 1)*(1 - 2-p) =

(1/2)*(2p - 2 + 2-p) =

2p-1 - 1 + 2-(p+1).

Now if p > 1, this is, to the nearest integer, 2p-1 - 1.

In other words, if we round the OP's expression to the nearest integer for p > 1, we have the criterion for base-2 pseudoprimes.

Of course, calculating 2p-1 - 1 as an exact integer for p > 100, say, may be more than the OP's code can handle, but that's not my problem.
Dr Sardonicus is offline   Reply With Quote
Old 2018-04-16, 15:54   #39
danaj
 
"Dana Jacobsen"
Feb 2011
Bangkok, TH

22×227 Posts
Default

A long int is greater than or equal to the size of an int. An int could be 16 bits, but on modern machines it will be 32. So a long might be 32 or 64 bits -- you have to test your machine or look up which model it uses (it's 64 on LP64 or ILP64, 32 on LLP64, ILP32, and LP32).

A long double is greater than or equal to the size of a double. On many platforms it is completely equivalent to a double. On some Intel platforms it is 80-bit, but that can depend on the compiler and flags (the storage size is typically 128-bit for alignment reasons). On some IBM machines it is full quad precision I believe. You need to use the quadmath library and its associated 'q' functions to get full 128-bit FP on all platforms. On Intel at least, it is substantially slower than the standard functions.

All that is tangential to the main argument against using this.
danaj is offline   Reply With Quote
Old 2018-04-17, 12:49   #40
Dr Sardonicus
 
Dr Sardonicus's Avatar
 
Feb 2017
Nowhere

110438 Posts
Default

Quote:
Originally Posted by Batalov View Post
The "if 0.5 * ... == 0" part is especially priceless.
It is very important to multiply by 0.5 before comparing to 0. "ORLY? Really, really."

Another excellent solution is to square something before comparing to 0. Really, really. And indeed, that's what is done here.

And finally, looks like there is a couple typos, too. (should be raising to power of p-1, not p.)
If n > 1, then 2^n =/= 1 (mod n). One proof is as follows:

Suppose n > 1, and let p be the least prime factor of n.

If p = 2, then n is even, so n does not divide the odd number 2^n - 1; i.e. 2^n =/= 1 (mod n).

If p > 2, let d be the multiplicative order of 2 (mod p). Then d divides p-1. Furthermore, as is well known, if k is a positive integer, and 2^k == 1 (mod p), then d divides k. Since d < p, and p is the least prime factor of n, d does not divide n. Therefore,

2^n =/= 1 (mod p),

which implies

2^n =/= 1 (mod n).

Note: Although there are nilpotent elements to some moduli, 2^n =/= 1 (mod p) also implies that (2^n - 1) (mod n) is not nilpotent.
Dr Sardonicus is offline   Reply With Quote
Old 2018-10-17, 00:11   #41
Godzilla
 
Godzilla's Avatar
 
May 2016

2·34 Posts
Default

looks at.... the algorithm and execute it .

With GMP

LIB = lib.h , libgmp.a


SUB : 0 is prime usually....





main.c





Code:
//main.c

#include <stdlib.h>
#include <stdio.h>
#include "lib/gmp.h"
#include "steps1.h"

#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#define MP_OKAY 0
#define MAX_DIGITS 10000

int main ( int argc , char **argv)

{

char io_string[MAX_DIGITS +1];



int result;

mpz_t num , tre , tre1 , agg , ris6 , ris5 , mod, un , agg1;
mpz_inits( num, tre , tre1 , agg , ris6 , ris5 , mod , un , agg1 , NULL );

mpf_set_default_prec(512);


mpz_add_ui(un,un,1);
mpz_add_ui(agg,agg,1);


printf("\nInserire numero(es.numero 341) : ");
scanf("%s", io_string);
result = mpz_set_str(num,io_string , 10);

if(result != MP_OKAY)
{

printf("\nImpossibile leggere numero!\n");

return EXIT_FAILURE;
}









while (mpz_cmp(num,agg) >= 0)
{

printf("\nNum : %s", mpz_get_str(io_string , 10 , agg));

//mpz_add(ris5,un,ris5);


printf("\nADD : %s", mpz_get_str(io_string , 10 , ris5));

mpz_div(tre1,ris5,agg);

printf("\nDIV : %s", mpz_get_str(io_string , 10 , tre1));

mpz_mul(agg1,agg,tre1);

printf("\nMUL : %s", mpz_get_str(io_string , 10 , agg1));

mpz_sub(ris6,ris5,agg1);


printf("\nSUB : %s", mpz_get_str(io_string , 10 , ris6));

mpz_add_ui(agg,agg,1);

mpz_add(ris5,ris5,ris5);
mpz_add(ris5,un,ris5);







//system("pause");
printf("\n\n");
}
//}
system("pause");
printf("\n\n");

//}

//system("pause");
//scanf("%s", io_string);
//printf("\n\n");

mpz_clears(num , tre , tre1 , agg , ris6 , ris5 , mod , un , agg1 ,NULL);

return EXIT_SUCCESS;
}





steps1.h




Code:
#ifndef __STEPS__
#define __STEPS__

#define MP_OKAY 0
#define MP_FAIL -1

int step0(mpz_t agg);
int step00(mpz_t un);
int step23(mpz_t ris5);
//prima moltiplicazione
int step001(mpz_t agg1, mpz_t agg , mpz_t tre1);

//prima divisione
int step003(mpz_t tre1 ,mpz_t agg , mpz_t tre );

//somma esempio tre piu tre
//int step004(mpz_t mod , mpz_t ris5);

//Aggiunge una unita a tre piu tre
int step908(mpz_t ris5 );
int step909(mpz_t ris5 , mpz_t un );
//sottrazione finale
int step006(mpz_t ris6, mpz_t agg1 ,mpz_t ris5);


//int step15(mpz_t a , mpz_t c6);
#include "steps2.c"

#endif


steps2.c



Code:
int step0(mpz_t agg)
{
mpz_add_ui(agg,agg,1);
}

int step00(mpz_t un)
{
mpz_add_ui(un,un,1);
}

//prima moltiplicazione
int step001(mpz_t agg1, mpz_t agg , mpz_t tre1)
{
mpz_mul(agg1,agg,tre1);
}

//prima divisione
int step003(mpz_t tre1 ,mpz_t agg , mpz_t tre )
{
mpz_div(tre1,tre,agg);
}

//somma esempio tre piu tre
//int step004(mpz_t mod , mpz_t ris5)
//{
//mpz_add(mod,ris5,ris5);
//}

//Aggiunge una unita a tre piu tre
int step908(mpz_t ris5 )
{
mpz_add(ris5,ris5,ris5);
}

int step909(mpz_t ris5 , mpz_t un )
{
mpz_add(ris5,un,ris5);
}


//sottrazione finale
int step006(mpz_t ris6, mpz_t agg1 ,mpz_t ris5)
{
mpz_sub(ris6,ris5,agg1);
}

OUTPUT EXAMPLE NUMBER .....13



Inserire numero(es.numero 341) : 13

Num : 1
ADD : 0
DIV : 0
MUL : 0
SUB : 0


Num : 2
ADD : 1
DIV : 0
MUL : 0
SUB : 1


Num : 3
ADD : 3
DIV : 1
MUL : 3
SUB : 0


Num : 4
ADD : 7
DIV : 1
MUL : 4
SUB : 3


Num : 5
ADD : 15
DIV : 3
MUL : 15
SUB : 0


Num : 6
ADD : 31
DIV : 5
MUL : 30
SUB : 1


Num : 7
ADD : 63
DIV : 9
MUL : 63
SUB : 0


Num : 8
ADD : 127
DIV : 15
MUL : 120
SUB : 7


Num : 9
ADD : 255
DIV : 28
MUL : 252
SUB : 3


Num : 10
ADD : 511
DIV : 51
MUL : 510
SUB : 1


Num : 11
ADD : 1023
DIV : 93
MUL : 1023
SUB : 0


Num : 12
ADD : 2047
DIV : 170
MUL : 2040
SUB : 7


Num : 13
ADD : 4095
DIV : 315
MUL : 4095
SUB : 0

Premere un tasto per continuare . . .

Last fiddled with by Godzilla on 2018-10-17 at 00:15
Godzilla is offline   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
500€ Reward for a proof for the Wagstaff primality test conjecture Tony Reix Wagstaff PRP Search 7 2013-10-10 01:23
Proof of Primality Test for Fermat Numbers princeps Math 15 2012-04-02 21:49
The fastest primality test for Fermat numbers. Arkadiusz Math 6 2011-04-05 19:39
PRIMALITY PROOF for Wagstaff numbers! AntonVrba Math 96 2009-02-25 10:37
A primality test for Fermat numbers faster than Pépin's test ? T.Rex Math 0 2004-10-26 21:37

All times are UTC. The time now is 04:38.


Sat Jul 17 04:38:10 UTC 2021 up 50 days, 2:25, 1 user, load averages: 1.90, 2.10, 2.19

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.