By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,143 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,143 IT Pros & Developers. It's quick & easy.

hello i want this phyton code in c language please help me

P: 1
Expand|Select|Wrap|Line Numbers
  1. def isPrim(n):
  2.     if n <=1 :
  3.         return False
  4.     if n <=3:
  5.         return True
  6.     else:
  7.         for x in range(3,n):
  8.             if(n%x==0):
  9.                 return False
  10.         return True
  11.  
  12. D,P=map(int,input().split())
  13. H=D/P
  14. N=H
  15. c=0
  16. while N>1:
  17.     i=0
  18.     count=0
  19.     while True:
  20.         if isPrim(int((i*H)+N)) and ((i*H)+N)<=D:
  21.             count=count+1
  22.         if i==(P-1): break
  23.         i+=1
  24.     if count == P: c+=1       
  25.     N-=1
  26. print(c)
Prime time again..
Aug 8 '20 #1
Share this Question
Share on Google+
1 Reply

Banfa
Expert Mod 5K+
P: 8,968
How much C do you know? Some us your attempt, we are not here to do your work for you.

Also at line 7 you have used too wide a range and it makes your code more inefficient than it need be.
Aug 8 '20 #2

Post your reply

Sign in to post your reply or Sign up for a free account.