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;
    }
    让未来到来 让过去过去
  • 相关阅读:
    [BZOJ1006]神奇的国度
    配置ubuntu18.04
    数据库的基本操作
    关于排序的算法——桶排序
    关于TCP/IP协议的记录
    laravel学习历程
    装箱问题
    01背包
    数字三角形
    统计单词的个数
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4734963.html
Copyright © 2011-2022 走看看