A 判断素数个数
需要注意x和y的大小比较!!
#include<iostream>
#include<cmath>
using namespace std;
bool isprime(int x)
{
int i;
for (i=2;i<=sqrt(x);i++)
if (x%i==0)
return false;
return true;
}
int main()
{
int n,i,m,count=0;
cin>>n>>m;
if (n>m)
swap(n,m);
for (i=n;i<=m;i++)
if (i==1)
continue;
else if (isprime(i))
count++;
cout<<count;
return 0;
}
C:岛屿周长
到LeetCode上找到了原题,以为要dfs,没想到是一道水题。一遍AC,没陷阱。
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water.