• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ArcTan

            dfs
            隨筆 - 16, 文章 - 117, 評論 - 6, 引用 - 0
            數(shù)據(jù)加載中……

            ACdream 1159(組合-遞推-優(yōu)化)

            1159: One Theorem, One Year

            Time Limit: 1 Sec  Memory Limit: 128 MB
            Submit: 21  Solved: 12
            [Submit][Status][Web Board]

            Description

            A number is Almost-K-Prime if it has exactly K prime numbers (not necessarily distinct) in its prime factorization. For example, 12 = 2 * 2 * 3 is an Almost-3-Prime and 32 = 2 * 2 * 2 * 2 * 2 is an Almost-5-Prime number. A number X is called Almost-K-First-P-Prime if it satisfies the following criterions:

            1.      X is an Almost-K-Prime and

            2.      X has all and only the first P (P ≤ K) primes in its prime factorization.

            For example, if K=3 and P=2, the numbers 18 = 2 * 3 * 3 and 12 = 2 * 2 * 3 satisfy the above criterions. And 630 = 2 * 3 * 3 * 5 * 7 is an example of Almost-5-First-4-Pime.

            For a given K and P, your task is to calculate the summation of Φ(X) for all integers X such that X is an Almost-K-First-P-Prime.

            Input

            Input starts with an integer T (≤ 10000), denoting the number of test cases.

            Each case starts with a line containing two integers K (1 ≤ K ≤ 500) and P (1 ≤ P ≤ K).

            Output

            For each case, print the case number and the result modulo

            1000000007

            .

            Sample Input

            3 3 2 5 4 99 45

            Sample Output

            Case 1: 10 Case 2: 816 Case 3: 49939643

            求出素數(shù)后然后,然后然后就是排列組合的問題了。
            dp[i][j]表示在前i個素數(shù)里選j個數(shù)相乘的和
            dp[i][j]= dp[i-1][j-k]*exp[i][k]   0<=k<=j求和
            這里邊算邊模
            a[i][j]表示在前i個素數(shù)里j個數(shù)組成結(jié)果,則
            a[i][j]=mul[i]*dp[i][j-1]
            這里也邊算模。

            #include<stdio.h>
            #include<string.h>
            #include<math.h>
            int pri
            [550],b[3705];  //這里之前是3500要錯哦
            long long dp[505][505],a[505][505];
            long long mod=1000000007;
            int GetPri()
            {
                int i
            ,j,tot;
                memset(b,0,sizeof(b));
                i=2;
                tot=0;    //寫了那么素數(shù)篩法了,居然會在這里載!!!!
                while (i<=3700)
                {
                    while (b
            [i])    i++;
                    pri[++tot]=i;
                    j=i;
                    while (j<=3700)
                    {
                        b
            [j]=1;
                        j+=i;
                    }
                }
                return 
            0;
            }

            int Cal()
            {
                int i
            ,j;
                long long sum,mul;
                dp[0][0]=1;
                for (i=1; i<=500 ; i++ )
                {
                    dp
            [i][0]=1;
                    sum=0;
                    for (j=1; j<=500 ; j++ )
                    {
                        sum
            =(sum*pri[i]+dp[i-1][j-1]*pri[i]) % mod;   //哎,方程的優(yōu)化,還是沒有經(jīng)驗啊!!這里之前我是寫了個三重的循環(huán)呢。可以迭代的啊。
                        dp[i][j]=(dp[i-1][j]+sum) % mod;
                    }
                }
                mul
            =1;
                for (i=1; i<=500 ; i++ )
                {
                    mul
            =mul*(pri[i]-1) % mod;    //方程優(yōu)化!!!
                    for (j=i; j<=500 ; j++ )
                        a[i][j]=mul*dp[i][j-i] % mod;
                }
            }

            int main()
            {
                int p
            ,cas,n,m;
                GetPri();
                Cal();
                scanf("%d",&p);
                cas=0;
                while (p--)
                {
                    scanf(
            "%d%d",&n,&m);
                    printf("Case %d: %lld\n",++cas,a[m][n]);
                }
                return 
            0;
            }


            總結(jié):方程的優(yōu)化,降低維數(shù)!!!!!!!!!!!!!!!!!!!!
            真的是弱爆了啊。。。。。。。。

            posted on 2012-04-29 17:15 wangs 閱讀(220) 評論(0)  編輯 收藏 引用 所屬分類: ACM-數(shù)學(xué)

            国产巨作麻豆欧美亚洲综合久久| 久久99国产精品久久99小说| 国产成人久久精品二区三区| 久久国产乱子伦精品免费午夜| 久久天天躁狠狠躁夜夜不卡| 香蕉久久夜色精品国产尤物| 久久99精品久久久久久久久久| 精品久久香蕉国产线看观看亚洲 | 欧美伊人久久大香线蕉综合 | 久久精品一区二区影院| 亚洲乱码精品久久久久..| 国产精品视频久久久| 久久久久亚洲av综合波多野结衣| 国产欧美久久久精品| 久久精品亚洲AV久久久无码| 精品久久久久久国产免费了| 精品国产乱码久久久久久郑州公司 | 香蕉久久久久久狠狠色| 国产激情久久久久影院| 97久久精品无码一区二区天美| 久久婷婷午色综合夜啪| 久久久免费观成人影院| 精品熟女少妇aⅴ免费久久| 久久伊人精品青青草原高清| 久久亚洲私人国产精品vA| 久久人人爽人人爽人人片av麻烦| a级毛片无码兔费真人久久| 亚洲成色999久久网站| 成人久久综合网| 国产精品久久久久久久久| 国产精品一久久香蕉产线看 | 久久青青草原精品国产| 久久久久无码精品国产| 三上悠亚久久精品| 国内精品久久久久影院日本| 久久香综合精品久久伊人| 亚洲色大成网站www久久九| 中文国产成人精品久久不卡| 99久久精品免费看国产一区二区三区 | 99久久精品免费看国产一区二区三区| 国产精品久久久久无码av|