[Brush question note 56] factorial decomposition

Source: Internet
Author: User
Description

Given two numbers m, n, where M is a prime number.

Returns the factorial of N (0 <= n <= 10000) to calculate the number of M.

Input
The first row is an INTEGER (0 <S <= 100), indicating the number of test data groups.
The next s row has two integers n and M.
Output

Number of output M.


Ideas:

N! The result is very large. Set n first! Is not feasible, according to n! = 1*2*3 *... * n * (n-1)

Interpret each number in the factorial in sequence, and determine whether it contains a prime number M and how many <=> while (I % key = 0) & I/key)


#include <stdio.h>#include <stdlib.h>int count_Prime(int n,int key){int i;    int t=key;    int temp;    int count=0;    for(i=1;i<=n;i++)    {temp=i;while((temp/t)&&(temp%t==0))        {count++;            temp=temp/t;            }    }    return count;}int main(){int Cases;    int value;    int key;    scanf("%d",&Cases);    while(Cases--)    {scanf("%d %d",&value,&key);        printf("%d\n",count_Prime(value,key));    }return 0;}


[Brush question note 56] factorial decomposition

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.