zoukankan      html  css  js  c++  java
  • Zball in Tina Town

    Zball in Tina Town

     
     Accepts: 356
     
     Submissions: 2463
     Time Limit: 3000/1500 MS (Java/Others)
     
     Memory Limit: 262144/262144 K (Java/Others)
    Problem 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 11 time as large as its original size. On the second day,it will become 22times as large as the size on the first day. On the n-th day,it will become nn 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 TT, representing the number of cases.

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

    Output

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

    Sample Input
    2
    3
    10
    Sample Output
    2
    0

     题意:一个球的原始体积是1,到第n天增大到它的n-1的n倍,体积就是阶乘的意思,结果让我们求n-1天的体积对n的余数,10的9次方,那么大。是,有规律

    如果n是素数那么余数就是n-1,如果不是素数对n的余数肯定是0,当然4除外,是2.

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #include<algorithm>
    
    using namespace std;
    
    #define N 100000
    #define INF 0xfffffff
    
    int num[N], k;
    int a[N] = {1, 1};
    
    void prim()
    {
        k = 0;
        //memset(num, 0, sizeof(num));
    
        for(int i = 2; i < N; i++)
        {
            if(!a[i])
                num[k++] = i;
            for(int j = i+i; j < N; j += i)
                a[j] = 1;
        }
    }
    
    int isprime(int n)
    {
        if(n == 0 || n == 1)
            return 0;
    
        for(int i = 0; (long long)num[i]*num[i] <= n; i++)
            if(n % num[i] == 0)
                return false;
        return true;
    }
    
    int main()
    {
        int t, n;
    
        scanf("%d", &t);
        prim();
    
        while(t--)
        {
            scanf("%d", &n);
            if(n <= 4)
                printf("2
    ");
            else if(isprime(n))
                printf("%d
    ", n-1);
            else
                puts("0");
        }
        return 0;
    }
    让未来到来 让过去过去
  • 相关阅读:
    LinkedList实现原理(JDK1.8)
    ArrayList实现原理(JDK1.8)
    java集合讲解
    MySQL系列:MySQL的基本使用
    MySQL系列:一句SQL,MySQL是怎么工作的?
    MySQL系列:走进数据库,相关概念你都明白吗?
    MySQL系列:Windows 下 MySQL 8.X 的安装
    SpringBoot系列:Spring Boot集成定时任务Quartz
    SpringBoot系列:Spring Boot定时任务Spring Schedule
    SpringBoot系列:Spring Boot异步调用@Async
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4734963.html
Copyright © 2011-2022 走看看