调皮的HR

2019/04/12 16:36
阅读数 0

如图:笔试题

# -*- coding: utf-8 -*-
"""
Created on Thu Apr 11 15:58:11 2019

@author: weilong
"""
import math
class Solution:
    def IsPrime(self,num):
        for i in range(2,num):
            if num%i == 0 and i<num:
                return False
        return True
    def NY(self,product):
        max_num = round(math.sqrt(product))
        prime = []
        for num in range(2,max_num):
            if self.IsPrime(num):
                prime.append(num)        
        for index in range(len(prime)):
            small_prime = prime[index]
            big_prime = product / small_prime
            if big_prime % 1 == 0.0:
                if self.IsPrime(int(big_prime)):
                    return int(big_prime),small_prime
    def CountOf3(self,ID):
        count = 0
        for num in range(ID):
            if num % 2:
                while num:
                    single = num % 10
                    if single == 3:
                        count += 1
                    num = num //10
        return count
if __name__ == '__main__':
    solution = Solution()
    product = 707829217
    big,small = solution.NY(product)
    print('WeChat ID:NY'+str(big)+str(small))
    ID = int(str(big)+str(small))
    Num3 = solution.CountOf3(ID)
    print('    3的个数:',Num3)
    

 

展开阅读全文
def
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部