Java的10,195个 194 184 182字节
n->{var L=new java.util.Stack();int i=1,k,x,s,r=0;for(;i++<n;){for(k=1;i%++k>0;);if(k==i)L.add(i);}for(x=L.size(),i=0;i<x;)for(k=i++,s=0;k<x;r+=s==n?1:0)s+=(int)L.get(k++);return r;}
-1个字节感谢@ceilingcat。
-10个字节感谢@SaraJ。
在线尝试。
说明:
n->{ // Method with integer as both parameter and return-type
var L=new java.util.Stack();
// List of primes, starting empty
int i=1,k,x,s, // Temp integers
r=0; // Result-counter, starting at 0
for(;i++<n;){ // Loop `i` in the range [2, `n`]
for(k=1; // Set `k` to 1
i%++k>0;); // Inner loop which increases `k` by 1 before every iteration,
// and continues as long as `i` is not divisible by `k`
if(k==i) // If `k` is now still the same as `i`; a.k.a. if `i` is a prime:
L.add(i);} // Add the prime to the List
for(x=L.size(), // Get the amount of primes in the List
i=0;i<x;) // Loop `i` in the range [0, amount_of_primes)
for(s=0, // (Re)set the sum to 0
k=i++;k<x; // Inner loop `k` in the range [`i`, amount_of_primes)
r+=s==n? // After every iteration, if the sum is equal to the input:
1 // Increase the result-counter by 1
: // Else:
0) // Leave the result-counter the same by adding 0
s+=(int)L.get(k++);
// Add the next prime (at index `k`) to the sum
return r;} // And finally return the result-counter
它基本上与Jelly或05AB1E的答案类似,仅相差 190字节。
这里,每个部位的比较,增加只是为了好玩(和明白为什么Java是如此冗长,而这些高尔夫球场的语言都是那么强大):
- 隐式地输入:(果冻:0字节);(05AB1E:0个字节)隐式 ; (Java 10:5个字节)
n->{}
- 创建以下范围内的素数列表
[2, n]
:(果冻:2个字节)ÆR
;(05AB1E:2个字节)ÅP
; (Java 10:95个字节)var L=new java.util.Stack();int i=1,k,x,s,r=0;for(;i++<n;){for(k=1;i%++k>0;);if(k==i)L.add(i);}
- 获取所有连续子列表:(果冻:1个字节)
Ẇ
;(05AB1E:1个字节)Œ
; (爪哇10:55个字节)for(x=L.size(),i=0;i<x;)for(k=i++;k<x;)
和(int)L.get(k++);
- 汇总每个子列表:(果冻:1个字节)
§
;(05AB1E:1个字节)O
; (爪哇10:9字节),s
和,s=0
与s+=
- 计数等于输入的那些值:(Jelly:1个字节)
ċ
;(05AB1E:2个字节)QO
; (Java 10:15个字节),r=0
和r+=s==n?1:0
- 隐式输出结果:(果冻:0字节);(05AB1E:0个字节)隐式 ; (Java 10:9个字节)
return r;
2æR
与ÆR