Leonardo's Prime Factors

Problems:Link of this problems


where range <1000000000

code:
#include<stdio.h>
int next_prime(int n)
{
    int i;
    for(i=2;i<n;i++)
    {
        if(n%i==0)
            break;
    }
    if(i==n)
        return n;
    else
        return next_prime(n+1);
}
int main()
{
    int T,s,cou=0;
    unsigned long long int p,n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld",&n);
        p=2;
        s=2;
        cou=0;
        while(n>=p)
        {
            s=next_prime(s+1);
            p*=s;
            cou++;
        }
        printf("%d\n",cou);
    }
}

Input :

  • 6
  • 1
  • 2
  • 3
  • 500
  • 5000
  • 10000000000

Output:

  • 0
  • 1
  • 1
  • 4
  • 5
  • 10

মন্তব্যসমূহ

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

Big Big mod

শিরোনামহীন গল্প

Dictionaries and Maps