• 反素数深度分析


    装载自:http://blog.csdn.net/ACdreamers/article/details/25049767

    小知识点:

    如果求约数的个数 756=2^2*3^3*7^1

    (2+1)*(3+1)*(1+1)=24

    基于上述结论,给出算法:按照质因数大小递增顺序搜索每一个质因子,枚举每一个质因子

    为了剪枝:

    性质一:一个反素数的质因子必然是从2开始连续的质数.

    因为最多只需要10个素数构造:2,3,5,7,11,13,17,19,23,29

    性质二:p=2^t1*3^t2*5^t3*7^t4.....必然t1>=t2>=t3>=....

    学习反素数的时候先遇到的问题。

    给定一个数,求一个最小的正整数,使得的约数个数为

    大概看懂了、。在每一层建树搜索。但还是不太能理解。

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 using namespace std;
     5 
     6 typedef unsigned long long ULL;
     7 const ULL INF = ~0ULL;  // 表示无穷大。
     8 
     9 int p[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; // 一个数一定能被拆成质数相乘的形式、
    10 
    11 int n;
    12 ULL ans;
    13 
    14 void dfs(int dept, ULL tmp, int num) { // dept表示搜索的深度。num是当前的数的约数个数。tmp表示当前走索表示的数、
    15     if (num > n) return; // 如果约数个数>n
    16     if (num == n && ans > tmp) ans = tmp; // 如果约数个数刚好是n.而且这个数比上一个数小、就记录下来、
    17     for (int i=1; i<=63; ++i) { // 其实我觉得是从0开始的,???
    18         if (ans / p[dept] < tmp) break; // 不知道为什么这里是循环结束的条件。或者说到这一层就结束了???
    19         dfs(dept+1, tmp *= p[dept], num*(i+1)); // i是代表这一层有多少个p[dept]这个因子、
    20     }
    21 }
    22 
    23 int main() {
    24     while(cin >> n) {
    25         ans = INF;
    26         dfs(0, 1, 1);
    27         cout << ans << endl;  // 尝试过用c语言的输出。没试出来,。。。???
    28     }
    29     return 0;
    30 }
  • 相关阅读:
    第二节:如何正确使用WebApi和使用过程中的一些坑
    nodejs中function*、yield和Promise的示例
    关于nodejs访问mysql的思考
    nodejs使用log4js记录日志
    nodejs初识
    Spring学习笔记(入门)
    mybatis使用注解开发
    MyBatis配置文件中的常用配置
    using 自动释放资源示例
    Java将byte[]和int的互相转换
  • 原文地址:https://www.cnblogs.com/icode-girl/p/4853884.html
Copyright © 2020-2023  润新知