• 2015 Multi-University Training Contest 10 hdu 5407 CRB and Candies


    CRB and Candies

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 453    Accepted Submission(s): 222


    Problem Description
     

    CRB has N different candies. He is going to eat K candies.
    He wonders how many combinations he can select.
    Can you answer his question for all $K(0 leq K leq N)$?
    CRB is too hungry to check all of your answers one by one, so he only asks least common multiple(LCM) of all answers.

    Input
    There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case there is one line containing a single integer N.
    $1 leq T leq 300$
    $1 leq N leq 10^6$

    Output
    For each test case, output a single integer – LCM modulo $1000000007(109+7)$.

    Sample Input
    5
    1
    2
    3
    4
    5

    Sample Output
    1
    2
    3
    12
    10

    Author
    KUT(DPRK)

    解题:看 crazyacking 的解释,涨姿势了

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const int maxn = 1000002;
     5 const int mod = 1000000007;
     6 bool np[maxn] = {true,true};
     7 int p[maxn],tot;
     8 void init(){
     9     for(int i = 2; i < maxn; ++i){
    10         if(!np[i]) p[tot++] = i;
    11         for(int j = 0; j < tot && i*p[j] < maxn; ++j){
    12             np[i*p[j]] = true;
    13             if(i%p[j] == 0) break;
    14         }
    15     }
    16 }
    17 int main(){
    18     init();
    19     int kase,n;
    20     scanf("%d",&kase);
    21     while(kase--){
    22         scanf("%d",&n);
    23         LL ret = 1;
    24         for(int i = 0; i < tot; ++i){
    25             for(LL j = p[i]; j <= n; j *= p[i])
    26                 if((n+1)%j) ret = ret*p[i]%mod;
    27         }
    28         printf("%I64d
    ",ret);
    29     }
    30     return 0;
    31 }
    View Code
  • 相关阅读:
    git clone GitLab 工程报错Repository not found
    vue + Element-ui 实现分页
    Element-ui 实现table的合计功能
    python 使用UUID库生成唯一ID
    css 设置overflow:scroll 滚动条的样式
    下载css-loader 安装及使用
    vue实现首页导航切换不同路由的方式(二)【使用vuex实现的】
    vue实现随机验证码功能
    vue实现首页导航切换不同路由的方式
    vue实现菜单切换
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4749673.html
Copyright © 2020-2023  润新知