zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    airflow 安装问题
    ACM-单词接龙
    ACM-AK吧!少年
    ACM-Alice and Bob
    ACM-Satellite Photographs
    ACM-Subset sum
    ACM-Special Array
    数据挖掘-回归分析
    数据库原理-数据库系统的结构
    数据库原理-几种数据模型
  • 原文地址:https://www.cnblogs.com/dll6/p/5777177.html
Copyright © 2011-2022 走看看