• HDU 5391 水题。


    E - 5
    Time Limit:1500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    Tina Town is a friendly place. People there care about each other. 

    Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes 1 time as large as its original size. On the second day,it will become 2 times as large as the size on the first day. On the n-th day,it will become n times as large as the size on the (n-1)-th day. Tina want to know its size on the (n-1)-th day modulo n. 

    Input

    The first line of input contains an integer T, representing the number of cases. 

    The following T lines, each line contains an integer n, according to the description. 
    T leq {10}^{5},2 leq n leq {10}^{9} 

    Output

    For each test case, output an integer representing the answer.

    Sample Input

    2
    3
    10

    Sample Output

    2
    0


    思路:用 long long 直接暴力打个表可以看到21以内的结果, 5以前的没什么规律, 5以后的只要是素数答案是n-1, 不是素数答案都是0。n的取值范围十的九次方, 一般这种题都是水题。

    代码:

    #include<stdio.h>
    #include<string.h>
    #include<math.h>

    #define N 110

    void judge(int n)//判断是否是素数。
    {
    int i, k, f = 0;
    k = (int)sqrt(n);

    for(i = 2; i <= k; i++)
    {
    if(n % i == 0)
    {
    printf("%d ", 0);
    f = 1;
    break;
    }
    }
    if(f ==0)
    printf("%d ", n-1);

    }

    int main()
    {
    int t, n;

    scanf("%d", &t);

    while(t--)
    {
    scanf("%d", &n);

    if(n == 2)
    printf("1 ");
    else if(n == 3 || n == 4)
    printf("2 ");
    else if( n == 5)
    printf("4 ");
    else
    {
    judge(n);
    }
    }

    return 0;
    }

  • 相关阅读:
    超参数调优
    集成学习(一)
    L1范数与L2范数
    HMM与CRF
    主题模型LDA
    性能评估指标
    java-jdk8下载及安装
    pandas相关性分析
    pandas小技巧
    Window—mysql下载及安装
  • 原文地址:https://www.cnblogs.com/dll6/p/5777177.html
Copyright © 2020-2023  润新知