forked from osamawaqar/HactoberFest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconjectures.cpp
More file actions
515 lines (435 loc) · 10.6 KB
/
Copy pathconjectures.cpp
File metadata and controls
515 lines (435 loc) · 10.6 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
#include <iostream>
using namespace std;
#include <ctime>
#include <cmath>
//QUESTION NO 1
//PART a)
// .
bool IsPrime(long long Number)
{
if (Number == 2)
{
return true;
}
else if (Number < 2)
{
return false;
}
long long Limit = Number / 2;
for (int counter = 2; counter <= Limit; counter++)
{
if (Number % counter == 0)
{
return false;
}
}
return true;
}
// .
bool IsPrimeFaster(long long Number)
{
if (Number == 2)
{
return true;
}
else if (Number < 2)
{
return false;
}
long long Limit = sqrt(Number);
for (int counter = 2; counter <= Limit; counter++)
{
if (Number % counter == 0)
{
return false;
}
}
return true;
}
//PART b)
bool P(long long n)
{
long long N = (n * n) + n + 41;
if (IsPrimeFaster(N) == true)
{
return true;
}
else if (IsPrimeFaster(N) == false)
{
return false;
}
}
//PART c)
void twinprime(long long range)
{
for (long long start = range; start > 0; start--)
{
if (IsPrimeFaster(start) == true && IsPrimeFaster(start - 2) == true)
{
cout << "Twin Primes: " << start << "," << start - 2 << endl;
break;
}
}
}
//Part c
//Problem 2
bool EularConjucture(long long a, long long b, long long c, long long d)
{
if (pow(a, 4) + pow(b, 4) + pow(c, 4) == pow(d, 4))
{
return true;
}
else if (pow(a, 4) + pow(b, 4) + pow(c, 4) != pow(d, 4))
{
return false;
}
}
//problem 3
//part a
bool ellipticcurve(long long a, long long b, long long c)
{
if (313 * (pow(a, 3) + pow(b, 3)) == pow(c, 3))
{
return true;
}
else if (313 * (pow(a, 3) + pow(b, 3)) != pow(c, 3))
{
return false;
}
}
//part a
//part b
void goldbach(long long even)
{
long long half = even / 2;
if (IsPrimeFaster(half) == true)
{
cout << "The even number with the sum of two prime numbers is: " << half << "+" << half << endl;
}
else if (IsPrimeFaster(half) == false)
{
long long p1, p2 = 0;
long long countx = 0, county = 0;
for (long long x = half, y = half; x > 0, y < INT_MAX; x--, y++, countx++, county++)
{
if (IsPrimeFaster(x) == true && IsPrimeFaster(y) == true && countx == county)
{
p1 = x;
p2 = y;
break;
}
}
cout << "The even number with the sum of two prime numbers: " << p1 << "+" << p2 << endl;
}
}
//part b
//part c
bool IsEven(long long Number)
{
if (Number % 2 == 0)
{
return true;
}
return false;
}
int Collatz(long long Number)
{
if (Number / 2 == 1)
{
cout << "The number that is shrunked by dividing it by 2 is " << Number << endl;
cout << "It shrunk to 1" << endl;
return 0;
}
else if (IsEven(Number) == true)
{
cout << "The number that is shrunked by dividing it by 2 is " << Number << endl;
long long Temp_for_Even = Number / 2;
cout << "The number shrunked is " << Temp_for_Even << endl;
return (Collatz(Temp_for_Even));
}
else if (IsEven(Number) == false)
{
cout << "The number that is tripled by multiplying it by 3 and adding 1 is " << Number << endl;
long long Temp_for_ODD = (3 * Number) + 1;
cout << "The number increased is" << Temp_for_ODD;
return (Collatz(Temp_for_ODD));
}
}
//part c
//problem 3
int main()
{
cout << "Enter the NUMER of the problem to check that problem (1 to 3)................." << endl;
int problem;
cin >> problem;
system("cls");
//problem 1
if (problem == 1)
{
cout << "Enter the part of the question you want to check. Enter a,b or c to check." << endl;
char part;
cin >> part;
system("cls");
//part a
if (part == 'a')
{
cout << "Enter n if you want to check by n/2 method otherwise enter s if you want to check by square root method: " << endl;
char check;
cin >> check;
if (check == 'n')
{
system("cls");
cout << "Enter the number you want to check" << endl;
long long number = 0;
cin >> number;
time_t begin, end;
time(&begin);
system("cls");
if (IsPrime(number) == true)
{
cout << "its a prime number" << endl;
}
else if (IsPrime(number) == false)
{
cout << "its not a prime number" << endl;
}
time(&end);
double difference = difftime(end, begin);
printf("time taken by function to get executed function() %.2lf seconds.\n", difference);
}
else if (check == 's')
{
system("cls");
cout << "Enter the number you want to check" << endl;
long long number = 0;
cin >> number;
time_t begin, end;
time(&begin);
system("cls");
if (IsPrimeFaster(number) == true)
{
cout << "its a prime number" << endl;
}
else if (IsPrimeFaster(number) == false)
{
cout << "its not a prime number" << endl;
}
time(&end);
double difference = difftime(end, begin);
printf("time taken by function to get executed function() %.2lf seconds.\n", difference);
}
//part a
}
//part b
else if (part == 'b')
{
cout << "Press u to enter user defined values to check if the proposition p(n)=n^2+n+41 is prime or not else press c to check at which number the proposition fails:" << endl;
char choice;
cin >> choice;
system("cls");
if (choice == 'u')
{
cout << "Enter the number n to check p(n)=n^2+n+41 is prime or not" << endl;
long long n;
cin >> n;
if (P(n) == true)
{
cout << "its a prime number" << endl;
}
else if (P(n) == false)
{
cout << "its not a prime number" << endl;
}
}
else if (choice == 'c')
{
for (int n = 0; n < INT_MAX; n++)
{
if (P(n) == false)
{
cout << "Claim failed at the number:" << n << endl;
break;
}
}
}
}
//part b
//part c
else if (part == 'c')
{
cout << "Enter the maximum range under which you want to get twin primes " << endl;
long long range;
cin >> range;
twinprime(range);
}
//partc
}
//problem 1
//Problem 2
else if (problem == 2)
{
cout << "Enter a to check first part of the question otherwise enter b to check second part" << endl;
char choice;
cin >> choice;
//part a
system("cls");
if (choice == 'a')
{
system("cls");
cout << "Enter a b c and d" << endl;
long long a, b, c, d;
cout << "Enter a:";
cin >> a;
cout << "Enter b:";
cin >> b;
cout << "Enter c:";
cin >> c;
cout << "Enter d:";
cin >> d;
system("cls");
if (EularConjucture(a, b, c, d) == true)
{
cout << "Conjucture satisfied" << endl;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
cout << "c=" << c << endl;
cout << "d=" << d << endl;
}
else if (EularConjucture(a, b, c, d) == false)
{
cout << "Conjucture Failed" << endl;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
cout << "c=" << c << endl;
cout << "d=" << d << endl;
}
}
//part a
//part b
else if (choice == 'b')
{
long long range = 2147383647;
for (int a = range; a > 0; a--)
{
for (int b = range; b > 0; b--)
{
for (int c = range; c > 0; c--)
{
for (int d = range; d > 0; d--)
{
if (EularConjucture(a, b, c, d) == true)
{
cout << "Finally" << endl;
cout << "Conjucture satisfied" << endl;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
cout << "c=" << c << endl;
cout << "d=" << d << endl;
}
}
}
}
}
// 2682440, 15365639, 18796760, 20615673. Solution after long term testing.
}
//part b
}
//problem2
//problem 3
else if (problem == 3)
{
cout << "Enter The part of the question you want to check (a,b,c)" << endl;
char part;
cin >> part;
system("cls");
//part a
if (part == 'a')
{
cout << "Press e to enter triptlet to check if it satisfies 313(a^3+b^3)=c^3.\n\nElse press t to find 3 tuple which satisfies given proposition:" << endl;
char option;
cin >> option;
system("cls");
if (option == 'e')
{
cout << "Enter a,b and c" << endl;
long long a, b, c;
cout << "Enter a:";
cin >> a;
cout << "Enter b:";
cin >> b;
cout << "Enter c:";
cin >> c;
system("cls");
if (ellipticcurve(a, b, c) == true)
{
cout << "Conjucture satisfied" << endl;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
cout << "c=" << c << endl;
}
else if (ellipticcurve(a, b, c) == false)
{
cout << "Conjucture Failed" << endl;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
cout << "c=" << c << endl;
}
}
else if (option == 't')
{
long long range = 2147383647;
for (int a = range; a > 0; a--)
{
for (int b = range; b > 0; b--)
{
for (int c = range; c > 0; c--)
{
if (ellipticcurve(a, b, c) == true)
{
cout << "Finally!!" << endl;
cout << "Conjucture satisfied" << endl;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
cout << "c=" << c << endl;
}
}
}
}
}
}
//part b
else if (part == 'b')
{
cout << "How many numbers you want to test :" << endl;
int limit;
cin >> limit;
system("cls");
for (int start = 0; start < limit; start++)
{
cout << "Enter only the even number you want to test: " << endl;
long long number;
cin >> number;
goldbach(number);
cout << endl;
}
}
//part b
else if (part == 'c')
{
cout << "How many numbers you want to test :" << endl;
int limit;
cin >> limit;
system("cls");
for (int start = 0; start < limit; start++)
{
cout << "Enter number you want to test: " << endl;
long long number;
cin >> number;
Collatz(number);
cout << endl;
}
}
}
//problem 3
system("pause");
}