#1和#4 WA 其他 AC 67分求救!

P1036 [NOIP2002 普及组] 选数

判断质数时,n<2时不是质数,但你这样就是1
by Hhy140516 @ 2024-05-10 20:49:43


@[Asun5678](/user/1271070) ```cpp #include <iostream> #include <cstdio> using namespace std; bool isprime(int a){ for(int i = 2; i * i <= a; i++) if(a % i == 0) return false; return true; } int n,k; int a[25]; long long ans; void dfs(int m, int sum, int startx){ if(m == k){ if(isprime(sum)) ans++; return ; } for(int i = startx; i < n; i++) dfs(m + 1, sum + a[i], i + 1); return ; } int main(){ scanf("%d%d",&n,&k); for(int i = 0; i < n; i++) scanf("%d",&a[i]); dfs(0, 0, 0); printf("%d\n",ans); return 0; } ```
by MESSI_ @ 2024-05-11 19:42:48


@[Hhy140516](/user/1176359) @[MESSI_](/user/972183) 感谢答复
by Wh1spers0fTheW1nd @ 2024-05-13 06:38:53


|