Hello everyone, you need to factor the number (defined). With small numbers everything works. How I try to work with big ones fails. The code is:
#include <iostream> #include <vector> #include <random> using namespace std; __int64 powmod(__int64 a, __int64 b, __int64 m) { unsigned __int64 res = 1; while (b > 0) if (b & 1) { res = (res * a) % m; --b; } else { a = (a * a) % m; b >>= 1; } return res % m; } void algorithm(__int64 a, __int64 b, __int64 p) { random_device rd; mt19937 gen(rd()); uniform_int_distribution <unsigned long long> dis(1, p); __int64 n = 11; vector<__int64> vector1(n); __int64 **mas = new __int64 *[n]; __int64 r = 0; __int64 e = n - 1; __int64 s = 1; vector1[0] = 2; vector1[1] = 3; vector1[2] = 5; vector1[3] = 7; vector1[4] = 11; vector1[5] = 13; vector1[6] = 17; vector1[7] = 19; vector1[8] = 23; vector1[9] = 29; vector1[10] = 31; for (__int64 i = 0; i < n; i++) mas[i] = new __int64[n]; for (__int64 i = 0; i < n; i++) for (__int64 j = 0; j < n; j++) mas[i][j] = 0; //выбор элемента, который еще не встречался for (__int64 i = 0; i < n; i++) { do { s = dis(gen); //возведение в степень и разложение числа r = powmod(a, s, p); while (e != -1) { if (r%vector1[e] == 0) { r /= vector1[e]; mas[i][e]++; } else e--; } if(r!=1) i--; e = n-1; } while (r != 1); } } void main() { algorithm(5, 43, 1073676287); } The value of s changes randomly, if not decomposed, then we change the value of s and try again to decompose, this is not indicated here. The decomposition itself goes in a while loop. If you take the module 503, then everything works fine. If more, then he can not. What is the problem?
do { } while. At the very first iteration of this loop, the inner loop bringseto-1. After that,ealways-1, i.e. furtherdo { } whiledoes not do anything meaningful at all - it just stupidly generates a new randomrand decreasesi. And so on, untilraccidentally becomes1. - AnT