1298-one theorem, one year

Source: Internet
Author: User

1298-one theorem, one year
PDF (中文版) Statistics Forum
Time Limit:2 second (s) Memory limit:32 MB

A number is almost-k-prime if it had exactly K Prime numbers (not necessarily distinct) in its Prime FAC Torization. For example, 2 * 2 * 3 are an almost-3-prime and 2 * 2 * 2 * 2 * 2 are 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 have all and only the first P (p≤k) primes in its prime factorization.

For example, if k=3 and p=2, the numbers = 2 * 3 * 3 and * = 2 * 2 * 3 satisfy the above Criteri Ons. and 630 = 2 * 3 * 3 * 5 * 7 is an example of almost-5-first-4-pime.

For a given K and P, your task was to calculate the summation of Φ (X) for all integers x such that's X is an almost-k-first-p-prime.

Input

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

Each case is starts with a line containing, 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 Output for Sample Input

3

3 2

5 4

99 45

Case 1:10

Case 2:816

Case 3:49,939,643

Note
    1. In mathematics Φ (X) means the number of relatively prime numbers with respect to X which is smaller tha n X. The numbers relatively prime if their GCD (greatest Common Divisor) is 1. For example, Φ (4), because the numbers, is relatively prime to are:1, 5, 7, 11.
    2. For the first case, K = 3 and P = 2 We had only such numbers which is almost-3-first-2-prime , 18=2*3*3 and 12=2*2*3. The result is therefore, Φ (12) +φ (+) = Ten.
Problem Setter:samir ahmedspecial thanks:jane Alam Jan idea: DP; state transition equation Dp[i][j]=dp[i-1][j-1]+dp[i][j-1];i represents the first prime I, J denotes the length of the prime factor consisting of the first prime number of primes, dp[i][j] The existence of all the numbers in accordance with this requirement; State interpretation: The number of the current end is put in the first prime, then its previous number is either its previous prime or himself. So DP first makes a table, and then according to the Euler function N ((1-1/P1) * (1-1/P2) .... Because Dp[i][j] is the same as the number of factors, and then (p1*p2* ...) The table dozen good an, put (p1-1) * (p2-1) *....bn play well so k=i,p=j, the straight is dp[j][i]* (An[j]/bn[j])%mod, and then Bn[i] with Fermat theorem converted to inverse, so finally dp[j][i]* (an[ J]*BN[J])%mod.
1#include <math.h>2#include <stdlib.h>3#include <stdio.h>4#include <algorithm>5#include <iostream>6#include <string.h>7#include <vector>8#include <map>9#include <math.h>Ten using namespacestd; OnetypedefLong LongLL; Atypedef unsignedLong Longll; - BOOLprime[ the]= {0}; - intsu[ -]; theLL dp[ -][ -]; -LL ola[ -]; -LL ola1[ -]; - ConstLL mod=1e9+7; +LL Quick (intNintm); - intMainvoid) + { A         inti,j,k,p,q; at          for(i=2; i<= -; i++) -         { -                  for(J=i; i*j<= the; J + +) -                 { -prime[i*j]=true; -                 } in         } -         intans=1; to          for(i=2; i<= the; i++) +         { -                 if(!Prime[i]) the                 { *su[ans++]=i; $                 }Panax Notoginseng         } -Memset (DP,0,sizeof(DP)); thedp[0][0]=1; +dp[1][1]=2; A          for(i=1; i<= -; i++) the         { +                  for(J=i; j<= -; J + +) -                 { $Dp[i][j]= (((dp[i][j-1]+dp[i-1][j-1]) (%mod) * (Su[i]))%MoD; $                 } -         } -ola[1]=su[1]; theola1[1]=su[1]-1; -          for(i=2; i<= -; i++)Wuyi         { theOla[i]= (su[i]*ola[i-1])%MoD; -Ola1[i]= (su[i]-1) *ola1[i-1]%MoD; Wu         } -          for(i=1; i<= -; i++) About         { $Ola[i]=quick (ola[i],mod-2); -         } -scanf"%d",&k); -         ints; A          for(s=1; s<=k; s++) +         { thescanf"%d%d",&p,&q); -LL cnt=Dp[q][p]; $LL cns=Ola[q]; theLL bns=Ola1[q]; theLL sum= ((CNT*CNS)%mod*bns)%MoD; theprintf"Case %d:", s); theprintf"%lld\n", sum); -         } in         return 0; the } theLL Quick (intNintm) About { theLL ans=1; theLL n=N; the          while(m) +         { -                 if(m&1) the                 {Bayians= (ans*n)%MoD; the                 } then= (n*n)%MoD; -M/=2; -         } the         returnans; the}

1298-one theorem, one year

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.