• [HDOJ5391]Zball in Tina Town


    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5391

      考的数论中的威尔逊定理,题目直接给出了威尔逊定理的表达式的语言描述。

      在初等数论中,威尔逊定理给出了判定一个自然数是否为素数的充分必要条件。即:当且仅当p为素数时:( p -1 )! ≡ -1 ( mod p ),但是由于阶乘是呈爆炸增长的,其结论对于实际操作意义不大。

      本题特别注意的是n=4的时候,要特判一下,是个trick。cout的话,也是会超时的。还有,本题数据给的是2<=n<=10^9,需要考虑的是如果打表的话,复杂的是O(nsqrt(n)),如果单独判的话是O(n),所以不选择打表。代码如下:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <map>
    #include <set>
    #include <cmath>
    #include <vector>
    #include <deque>
    #include <queue>
    
    using namespace std;
    typedef long long LL;
    
    int main() {
        int T;
        scanf("%d", &T);
        while(T--) {
            int flag = 0;
            int n;
            scanf("%d", &n);
            int m = int(sqrt(n));
            for (int i = 2; i < m; i++)
            {
                if (n % i == 0)
                {
                    flag++;
                    break;
                }
            }
            if(n == 0 || n == 1) {
                printf("1
    ");
            }
            else if(n == 2) {
                printf("2
    ");
            }
            else if(!flag) {
                printf("%d
    ", n-1);
            }
            else {
                printf("0
    ");
            }
        }
    }
    View Code
  • 相关阅读:
    2015总结篇
    Android应用性能优化实践
    Android国外学习资源汇总
    直接拿来用!十大Material Design开源项目
    selenium12-读取文件 excel
    selenium11-自动化练习读取文件txt
    selenium10-python3部分代码复习
    selenium09-自动化练习案例
    selenium08-测试用例模块化与数据分离
    selenium07-处理 alter 对话框
  • 原文地址:https://www.cnblogs.com/kirai/p/4733400.html
Copyright © 2020-2023  润新知