NC14615. Number
描述
输入描述
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 numberPython3 解法, 执行用时: 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; }