• 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
  • 相关阅读:
    *循环-04. 验证“哥德巴赫猜想”
    循环-03. 求符合给定条件的整数集
    *循环-01. 求整数段和【help】
    分支-15. 日K蜡烛图
    分支-14. 简单计算器
    *分支-13. 计算天数
    *分支-12. 计算火车运行时间
    自我介绍
    JAVA WEB第0课
    Forward团队-爬虫豆瓣top250项目-成员简介与分工
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4749673.html
Copyright © 2020-2023  润新知