📄 brute.cpp
字号:
/*
* Program to factor numbers using brute force.
* Copyright (c) 1988-1997 Shamus Software Ltd.
*
* Requires: big.cpp
*/
#include <iostream>
#include "big.h"
using namespace std;
#define LIMIT 10000
#ifndef MR_NOFULLWIDTH
Miracl precision=50;
#else
Miracl precision(50,MAXBASE);
#endif
int main()
{
int n,p;
Big x;
miracl *mr=&precision;
gprime(LIMIT); /* generate all primes < LIMIT */
cout << "input number to be factored\n";
cin >> x;
n=0;
p=mr->PRIMES[0];
cout << "factors are ";
forever
{ /* try division by each prime */
if (x%p==0)
{ /* factor found */
x/=p;
cout << "\nprime factor " << p << flush;
if (x==1) return 0;
continue;
}
if ((x/p)<=p)
{ /* must be prime */
cout << "\nprime factor " << x << "\n";
return 0;
}
p=mr->PRIMES[++n];
if (p==0) break;
}
if (prime(x)) cout << "\nprime factor " << x << "\n";
else cout << "\ncomposite factor " << x << "\n";
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -