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;
    }
    让未来到来 让过去过去
  • 相关阅读:
    2006百度之星
    使用StretchBlt之前一定要用SetStretchBltMode(COLORONCOLOR)
    算法学习建议(转)
    让ARM开发板上SD卡里的程序开机自动运行
    我的Dll(动态链接库)学习笔记
    WinCE 应用程序开机自动运行的又一种方法
    讲讲volatile的作用
    用Platform builder定制WinCE系统
    MFC如何高效的绘图
    利用c语言编制cgi实现搜索
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4734963.html
Copyright © 2011-2022 走看看