zoukankan      html  css  js  c++  java
  • HDU 4351

    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  time as large as its original size. On the second day,it will become  times as large as the size on the first day. On the n-th day,it will become  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 , representing the number of cases. 

    The following  lines, each line contains an integer , according to the description. 
     

    Output

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

    Sample Input

    2
    3
    10

    Sample Output

    2
    0
    规律题,把前20都列举一遍会发现,
    当n>4时
    当n是素数时的答案是n-1;
    当n为其他数时,答案为0
     1 #include <cstring>
     2 #include <cstdio>
     3 #include <iostream>
     4 #include <algorithm>
     5 #include <cmath>
     6 #include <stack>
     7 #include <vector>
     8 #include <queue>
     9 #include <cmath>
    10 using namespace std;
    11 #define N 10005
    12 typedef long long LL;
    13 int a[N];
    14 bool prim(int n)
    15 {
    16     int f = 0;
    17     int k = (int)sqrt(n);
    18     for(int i=2;i<=k;i++)
    19     {
    20         if(n % i == 0)
    21         {
    22             f = 1;
    23             break;
    24         }
    25     }
    26     if(f==1)
    27         return 0;
    28     return 1;
    29 
    30 }
    31 int main()
    32 {
    33     int n;
    34     int t;
    35     scanf("%d", &t);
    36     while(t--)
    37     {
    38         scanf("%d",&n);
    39         if(n==1)
    40             printf("1
    ");
    41         else if(n==4)
    42             printf("2
    ");
    43         else if(prim(n))
    44             printf("%d
    ",n-1);
    45         else
    46             printf("0
    ");
    47 
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    Mybatis原理
    周六上课随记
    第一次外包面试
    复习所想
    如何解决高并发下的超卖问题
    Tomcat架构解析
    即将逝去的25岁
    go 刷算法第一题——反转字符串
    JavaScript杂货
    jdk17新特性
  • 原文地址:https://www.cnblogs.com/biu-biu-biu-/p/5777174.html
Copyright © 2011-2022 走看看