列表

详情


NC14615. Number

描述

We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), and prime fourth power(四次方).
The first four Shuaishuai numbers are:

How many Shuaishuai numbers in [1,n]? (1<=n<=50 000 000)

输入描述

The input will consist of a integer n.

输出描述

You should output how many Shuaishuai numbers in [1...n]

示例1

输入:

28

输出:

1

说明:

There is only one Shuaishuai number

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Python3 解法, 执行用时: 2148ms, 内存消耗: 73980K, 提交时间: 2022-04-24 23:50:14

def check(i,j,k):
    return 
n = int(input())
up = int(n**.5)
up2 = int(n**(1/3))
prime_list = [2]
for i in range(3,up+1,2):
    if all(i%j for j in prime_list):
        prime_list.append(i)
index = sum(1 for i in prime_list if up2 >= i)-1
s = set()
for i in prime_list:
    for j in prime_list[:index+1]:
        for k in prime_list:
            num = i**2 + j**3 + k**4
            if n >= num:
                s.add(num)
            else: break
print(len(s))   

C++ 解法, 执行用时: 247ms, 内存消耗: 49328K, 提交时间: 2022-06-11 20:23:00

#include<iostream>
using namespace std;
int li[7100],idx,n,sum;
bool a[50000010];
int main()
{
    cin>>n;
    for(int i=2;i<=7071;i++)
      for(int j=2;i*j<=7071;j++)li[i*j]=1;
    for(int i=2;i<=7071;i++)
    for(int j=2;j<=368;j++)
    for(int k=2;k<=84;k++)
        if(!li[i]&&!li[j]&&!li[k]&&i*i+j*j*j+k*k*k*k<=n)
        {         if(a[i*i+j*j*j+k*k*k*k]==0)sum++;
            a[i*i+j*j*j+k*k*k*k]=1;
}
    cout<<sum;
    return 0;
}

上一题