zoukankan      html  css  js  c++  java
  • ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies

    There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N)(1...N), and each time a child is invited, Miss Li randomly gives him some candies (at least one). The process goes on until there is no candy. Miss Li wants to know how many possible different distribution results are there.

    Input

    The first line contains an integer TT, the number of test case.

    The next TT lines, each contains an integer NN.

    1 le T le 1001≤T≤100

    1 le N le 10^{100000}1≤N≤10100000

    Output

    For each test case output the number of possible results (mod 1000000007).

    样例输入复制

    1
    4

    样例输出复制

    8

    题目来源

    ACM-ICPC 2018 焦作赛区网络预赛

    通过打表可知,答案是2^n-1 ,但是n又太大,直接计算会超时。所以这里就需要用到欧拉函数了。话不多说上代码:

    #include<iostream>
    #include<cstring>
    #include<string>
    #include<algorithm>
    using namespace std;
    char a[1005][1005];
    int main()
    {
        int n;
        a[0][0] = '1';
        int before = 1;
        for(int i = 1;i <= 100; ++i)
        {
            int k = 0;
            int mod = 0;
            for(int j = 0;j < before;++j)
            {
                a[i][k++] = ((a[i - 1][j] - '0') * 2 + mod) % 10+48;
                mod = (((a[i - 1][j] - '0') * 2) + mod) / 10;
            }
            if(mod)
                a[i][k++] = mod + 48;
            before=k;
        }
        while(cin>>n)
        {
            int len=strlen(a[n]);
            for(int i=len-1;i>=0;--i)
                cout<<a[n][i];
            cout<<endl;
        }
    }
    
  • 相关阅读:
    ubuntu下crontab启动,重启,关闭命令
    解决ubuntu16.04下boot空间不足的方法
    Go语言变量作用域
    Go语言函数
    xftp取消自动更新
    nginx下http如何转https访问
    mysql 5.7.22 zip安装
    微服务本机搭建
    微服务集成mybatis问题
    eclipse导入本地maven项目时,有的项目的结构是文件夹的机构
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451417.html
Copyright © 2011-2022 走看看