找回密码
 欢迎注册
查看: 15093|回复: 8

[求助] 寻个 分解质因数V2.04破解版

[复制链接]
发表于 2011-2-24 13:20:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?欢迎注册

×
如题,如果谁有麻烦发我邮箱 1183812371@qq.com
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2011-2-24 16:49:29 | 显示全部楼层
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2011-2-24 17:00:44 | 显示全部楼层
网上的我找过了,下载不了。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2011-2-24 18:20:01 | 显示全部楼层
3# 不穿男裤的酷男 很难下载吗?呵呵 v24.jpg
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2011-2-24 19:21:50 | 显示全部楼层
4楼的朋友麻烦发我邮箱,谢谢、
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2011-2-25 09:52:21 | 显示全部楼层
5# 不穿男裤的酷男
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2011-3-2 02:40:33 | 显示全部楼层
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. unsigned int MPow(unsigned int factor, unsigned int n)
  5. {
  6. unsigned int result = 1;
  7. for (unsigned int i = 0; i < n; ++i)
  8. result *= factor;
  9. return result;
  10. }
  11. // common list declaration and implemention
  12. template <typename T>
  13. class SimpleList
  14. {
  15. private:
  16. struct SimpleListNode
  17. {
  18. explicit SimpleListNode (const T &obj, SimpleListNode *pt = 0) : data(obj), next(pt) { }
  19. T data;
  20. SimpleListNode *next;
  21. };
  22. public:
  23. class Iterator
  24. {
  25. public:
  26. explicit Iterator(SimpleListNode *pNode = 0) : node(pNode) { }
  27. T &operator *() { return node->data; }
  28. T *operator ->() const { return &(node->data); }
  29. Iterator &operator ++()
  30. {
  31. node = node->next;
  32. return *this;
  33. }
  34. friend bool operator == (const Iterator &it1, const Iterator &it2)
  35. {
  36. return it1.node == it2.node;
  37. }
  38. friend bool operator != (const Iterator &it1, const Iterator &it2)
  39. {
  40. return !(it1 == it2);
  41. }
  42. public:
  43. SimpleListNode *node;
  44. };
  45. class ConstIterator
  46. {
  47. public:
  48. explicit ConstIterator(const SimpleListNode *pNode = 0) : node(pNode) { }
  49. const T &operator *() const { return node->data; }
  50. const T *operator ->() const { return &(node->data); }
  51. ConstIterator &operator ++()
  52. {
  53. node = node->next;
  54. return *this;
  55. }
  56. friend bool operator == (const ConstIterator &it1, const ConstIterator &it2)
  57. {
  58. return it1.node == it2.node;
  59. }
  60. friend bool operator != (const ConstIterator &it1, const ConstIterator &it2)
  61. {
  62. return !(it1 == it2);
  63. }
  64. public:
  65. const SimpleListNode *node;
  66. };
  67. SimpleList()
  68. : head(0), tail(0) { }
  69. SimpleList(const SimpleList &lst)
  70. : head(0), tail(0)
  71. {
  72. append(lst);
  73. }
  74. ~SimpleList()
  75. {
  76. clear();
  77. }
  78. SimpleList & operator = (const SimpleList &lst)
  79. {
  80. clear();
  81. append(lst);
  82. }
  83. ConstIterator begin() const { return ConstIterator(head); }
  84. Iterator begin() { return Iterator(head); }
  85. ConstIterator end() const { return ConstIterator(0); }
  86. Iterator end() { return Iterator(0); }
  87. ConstIterator last() const { return ConstIterator(tail); }
  88. Iterator last() { return Iterator(tail); }
  89. void append(const SimpleList &lst)
  90. {
  91. for (SimpleListNode *p = lst.head; p; p = p->next)
  92. push_back(p->data);
  93. }
  94. void clear()
  95. {
  96. while(!empty())
  97. {
  98. SimpleListNode *p = head->next;
  99. delete head;
  100. head = p;
  101. }
  102. }
  103. unsigned int size() const
  104. {
  105. unsigned int sz = 0;
  106. for (const SimpleListNode *p = head; p; p = p->next)
  107. ++sz;
  108. return sz;
  109. }
  110. bool empty() const
  111. {
  112. return head == 0;
  113. };
  114. void push_front(const T &data)
  115. {
  116. head = new SimpleListNode(data, head);
  117. if(!tail)
  118. tail = head;
  119. }
  120. void push_back(const T &data)
  121. {
  122. if(tail)
  123. {
  124. tail->next = new SimpleListNode(data);
  125. tail = tail->next;
  126. }
  127. else
  128. {
  129. head = tail = new SimpleListNode(data);
  130. }
  131. }
  132. void pop_front()
  133. {
  134. SimpleListNode *tmp = head;
  135. if(head == tail)
  136. head = tail = 0;
  137. else
  138. head = head->next;
  139. delete tmp;
  140. }
  141. void pop_back()
  142. {
  143. if(head == tail)
  144. {
  145. delete head;
  146. head = tail = 0;
  147. }
  148. else
  149. {
  150. SimpleListNode *tmp;
  151. for(tmp = head; tmp->next != tail; tmp = tmp->next)
  152. ;
  153. delete tail;
  154. tail = tmp;
  155. tail->next = 0;
  156. }
  157. }
  158. private:
  159. SimpleListNode *head, *tail;
  160. };
  161. class MFactorCalulator
  162. {
  163. public:
  164. typedef SimpleList<unsigned int> MPrimeList;
  165. struct MFactor
  166. {
  167. MFactor(unsigned int fct, unsigned rep = 0)
  168. : factor(fct), repeat(rep) {}
  169. unsigned int factor;
  170. unsigned int repeat;
  171. };
  172. typedef SimpleList<MFactor> MFactorList;
  173. struct MPerfectNumber
  174. {
  175. MPerfectNumber(unsigned int num, const MFactorList &factorList)
  176. : number(num), factors(factorList) {}
  177. unsigned int number;
  178. MFactorList factors;
  179. };
  180. typedef SimpleList<MPerfectNumber> MPerfectNumberList;
  181. public:
  182. MFactorCalulator(unsigned int upper)
  183. : mUpper(upper) {}
  184. const MPrimeList &PrimeList() const
  185. {
  186. return mPrimeChain;
  187. }
  188. const MPerfectNumberList &PerfectNumberList() const
  189. {
  190. return mPerfectNumberChain;
  191. }
  192. void DoCalculate()
  193. {
  194. FindPrimes(mUpper);
  195. FindPerfectNumber(mUpper);
  196. }
  197. private:
  198. unsigned int mUpper;
  199. MPrimeList mPrimeChain;
  200. MPerfectNumberList mPerfectNumberChain;
  201. void FindPrimes(unsigned int upper)
  202. {
  203. mPrimeChain.clear();
  204. mPrimeChain.push_back(2);
  205. mPrimeChain.push_back(3);
  206. for (unsigned int i = 5; i <= upper; i += 2)
  207. {
  208. for (MPrimeList::Iterator it = ++mPrimeChain.begin(); it != mPrimeChain.end() && (i % *it); ++it)
  209. {
  210. if (*it * *it > i)
  211. {
  212. mPrimeChain.push_back(i);
  213. break;
  214. }
  215. }
  216. }
  217. }
  218. void FindPerfectNumber(unsigned int upper)
  219. {
  220. for (unsigned int i = 2; i <= upper; ++i)
  221. CheckPerfectNumber(i);
  222. }
  223. bool CheckPerfectNumber(unsigned int number)
  224. {
  225. unsigned int quotient = number;
  226. MFactorList factor_list;
  227. for (MPrimeList::Iterator it = mPrimeChain.begin(); it != mPrimeChain.end(); ++it)
  228. {
  229. if (*it * *it > quotient)
  230. {
  231. MFactor factor1(quotient, 0);
  232. factor1.repeat = 1;
  233. factor_list.push_back(factor1);
  234. break;
  235. }
  236. MFactor factor(*it, 0);
  237. while (quotient % *it == 0)
  238. {
  239. ++factor.repeat;
  240. quotient /= *it;
  241. }
  242. if (factor.repeat > 0)
  243. factor_list.push_back(factor);
  244. }
  245. if (CalculateFactorSum(factor_list) == 2 * number)
  246. {
  247. mPerfectNumberChain.push_back(MPerfectNumber(number, factor_list));
  248. return true;
  249. }
  250. return false;
  251. }
  252. unsigned int CalculateFactorSum(const MFactorList &chain)
  253. {
  254. unsigned int chainsize = chain.size();
  255. MFactorList::ConstIterator *factor_arr = new MFactorList::ConstIterator[chainsize];
  256. unsigned int* counter = new unsigned int[chainsize + 1]; // counter[chainsize] is to quit loop
  257. MFactorList::ConstIterator p = chain.begin();
  258. for (unsigned int i = 0; i < chainsize; ++i, ++p)
  259. {
  260. factor_arr[i] = p;
  261. counter[i] = 0;
  262. }
  263. counter[chainsize] = 0;
  264. unsigned int sum = 0;
  265. while (!counter[chainsize]) // use the last element to quit loop
  266. {
  267. unsigned mix_product = 1;
  268. for (unsigned j = 0; j < chainsize; ++j)
  269. mix_product *= MPow(factor_arr[j]->factor, counter[j]);
  270. sum += mix_product;
  271. ++counter[0];
  272. for (j = 0; (j < chainsize) && (counter[j] > factor_arr[j]->repeat); ++j)
  273. {
  274. counter[j] = 0;
  275. ++counter[j + 1];
  276. }
  277. }
  278. delete []factor_arr;
  279. delete []counter;
  280. return sum;
  281. }
  282. };
  283. int main()
  284. {
  285. cout << "Input max number: ";
  286. int upper;
  287. cin >> upper;
  288. MFactorCalulator calc(upper);
  289. calc.DoCalculate();
  290. for (MFactorCalulator::MPerfectNumberList::ConstIterator it = calc.PerfectNumberList().begin();
  291. it != calc.PerfectNumberList().end(); ++it)
  292. {
  293. cout << it->number << " = ";
  294. for (MFactorCalulator::MFactorList::ConstIterator itFactor = it->factors.begin();
  295. (itFactor.node)->next != (it->factors.end()).node; ++itFactor)
  296. {
  297. cout << itFactor->factor << '^' << itFactor->repeat;
  298. cout << " * ";
  299. }
  300. cout << itFactor->factor << '^' << itFactor->repeat;
  301. cout << endl;
  302. }
  303. return 0;
  304. }
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-11-3 18:15:28 | 显示全部楼层
还有拿这个骗钱的东东????
叫PARI无地自容啊。。。。。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-11-3 18:17:46 | 显示全部楼层
本来想去下载比较下跟PARI的差异,看到最大只能分解29位,我就笑了。。。。。


毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-11-21 23:06 , Processed in 0.028727 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表