3.5w+
社区成员
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int num)
{
if(num == 2 || num == 3) return true;
if(num % 6 != 1 && num % 6 != 5) return false;
for(int i = 5; i <= sqrt(num); i += 6) {
if(num % i == 0 || num % (i+2) == 0)
return false;
}
return true;
}
int main()
{
int i = 2, cnt = 0;
while(true) {
if(isPrime(i)) cnt++;
if(cnt == 100002) {
cout << i << endl;
break;
}
i ++ ;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int ans = 0;
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
while(next_permutation(a, a + 10))
{
for(int i = 1; i < 10; i ++ )
if(a[i] == a[i - 1] + 1 || a[i] == a[i - 1] - 1) goto out;
ans ++;
out:;
}
cout << ans;
return 0;
}