Q4

问题:

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 ×99.

Find the largest palindrome made from the product of two 3-digit numbers.

第一次代码:

def pro_palin (n):
    s_str='{0}'.format(n)
    d_str=s_str[::-1]
    sum=0
    n_len=len(s_str)
    for i in d_str :
         sum=sum*10+int(i)
    return n*10**(n_len)+sum
def ismatched (n,index):
    divisor=2
    product=1
    while product!=n:
         print n,product
         if n/(10**(index-1))>0 and  n/(10**(index-1))<10 and product/(10**(index-1))>0 and product/(10**(index-1))<10:
                   print n,product
                   return True 
         while  n%divisor==0:
              if n/(10**(index-1))>0 and  n/(10**(index-1))<10 and product/(10**(index-1))>0 and product/(10**(index-1))<10:
                   print n,product,
                   return True              
              product*=divisor
              n=n/divisor
         divisor+=1
    return False

     
       
          
    
     
############主程序################
if __name__=='__main__': 
    ra=range(900,1000)[::-1]
    #print ra
    """
    for  item in ra :
         
         pralindro=pro_palin(item)
         #print pralindro         
         if ismatched(pralindro,3):
              print item
    """
    print ismatched(9009,2)
    
有问题找不到,99*91所以,我这肯定有问题。

我最终的代码

a

def pro_palin (n):
    s_str='{0}'.format(n)
    d_str=s_str[::-1]
    sum=0
    n_len=len(s_str)
    for i in d_str :
         sum=sum*10+int(i)
    return n*10**(n_len)+sum
def ismatched (n,index):
    divisor=2
    product=1
    ra=range(10**(index-1),10**index)[::-1]
    for i in ra :
         a,remain=divmod(n,i)
         if remain==0 and a/10**(index-1)>0 and a/10**(index-1)<10:
              print i,a
              return True
    return False    
############主程序################
if __name__=='__main__': 
    ra=range(900,1000)[::-1]
    #print ra
    
    for  item in ra :
         
         pralindro=pro_palin(item)
         #print pralindro         
         if ismatched(pralindro,3):
              print pralindro
    
    print ismatched(9009,2)
别人牛人的解答:

The palindrome can be written as:abccbaWhich then simpifies to:100000a + 10000b + 1000c + 100c + 10b + aAnd then:100001a + 10010b + 1100cFactoring out 11, you get:11(9091a + 910b + 100c)So the palindrome must be divisible by 11. Seeing as 11 is prime, at least one of the numbers must be divisible by 11. So brute force in Python, only with less numbers to be checked:

Python
Hide Code
def c():
   max = maxI = maxJ = 0
   i = 999
   j = 990
   while (i > 100):
      j = 990
      while (j > 100):
         product = i * j
         if (product > max):
            productString = str(product)
            if (productString == productString[::-1]):
               max = product
               maxI = i
               maxJ = j
         j -= 11
      i -= 1
   return max, maxI, maxJ
Returns an answer in 0.016 secs.



### 关于 Ollama Q4 的技术信息 Ollama 是一种用于管理和部署本地大型语言模型 (LLM) 的工具,其灵活性和易用性使其成为开发者社区中的热门选择。关于 Ollama Q4 的具体技术信息和技术资料,可以从以下几个方面进行探讨: #### 1. **Ollama Q4 的背景** Q4 模型通常指的是基于量化技术优化后的 LLM 版本,旨在减少内存占用并提高推理效率[^1]。这些模型经过特定的量化处理(如 INT8 或者更低精度),能够在性能损失较小的情况下显著降低硬件需求。 对于 Ollama 支持的 Q4 类型模型,官方文档并未单独列出名为 “Q4” 的独立模型类别;然而,许多第三方贡献的模型可能采用类似的命名方式来表示它们的量化级别。因此,在查找相关资源时,建议关注支持量化的通用方法以及对应的模型列表[^3]。 #### 2. **下载与安装** 如果需要获取适合 Ollama 平台使用的 Q4 模型文件,可以通过以下途径完成: - 访问 Hugging Face Model Hub 等开源平台寻找已适配为 GGUF/Safetensors 格式的预训练权重; - 利用 `ollama pull` 命令拉取远程仓库中可用的轻量化版本。例如: ```bash ollama pull llama2:q4_0 ``` 上述命令尝试加载由 Meta 开发并通过四比特量化压缩过的 LLaMA v2 变体[^4]。 注意:并非所有公开发布的模型都提供明确标注为“Q4”的变种形式,请仔细阅读描述页面确认实际参数配置后再决定是否选用。 #### 3. **使用教程** 针对已经成功导入系统的 Q4 模型实例化操作流程如下所示: ```python import openai openai.api_base = "http://localhost:11434" openai.api_key = "sk-yourkey" response = openai.ChatCompletion.create( model="llama2-q4", messages=[{"role": "user", "content": "你好!"}, {"role": "assistant", "content": ""}] ) print(response['choices'][0]['message']['content']) ``` 此脚本片段展示了如何借助 OpenAI Compatible API 调用运行在本地服务器上的指定名称(此处假设为 'llama2-q4')的服务端点[^2]。 --- ###
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值