两题水题:

1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数。

2.定义F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2) 让你判断第n项是否能被3整除。

1.ZOJ 2723 Semi-Prime

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1723

打表即可。

#include<cstdio>
const int MAXN=500000+10;
bool prime[MAXN]={0};
int num[MAXN],len;
int main()
{
for(int i=2;i*i<MAXN;i++)
if(!prime[i])
for(int j=i;j*i<MAXN;j++)
prime[i*j]=1; for(int i=2;i<MAXN;i++)
if(!prime[i])
num[len++]=i; int n;
while(~scanf("%d",&n))
{
int cnt=0,cur=0;
while(n!=1)
{
while( n % num[cur]==0)
{
cnt++;
n/=num[cur];
}
cur++;
if(cur >= len /*|| cnt >2*/ )
break;
}
if(cnt==2)
puts("Yes");
else
puts("No");
}
return 0;
}

2.ZOJ 2060 Fibonacci Again

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1060

不mod 3 会溢出。

方法1:直接打表

#include<cstdio>
const int MAXN=1000000+2;
int f[MAXN];
int main()
{
f[0]=7%3;f[1]=11%3;
for(int i=2;i<MAXN;i++)
f[i]=(f[i-1]%3+f[i-2]%3)%3; int n;
while(~scanf("%d",&n))
{
if(f[n] ==0)
puts("yes");
else
puts("no");
}
return 0;
}

方法2:

看上面的打表,可发现每8项一循环。

#include<cstdio>
const int MAXN=8;
int f[MAXN];
int main()
{
f[0]=7%3;f[1]=11%3;
for(int i=2;i<8;i++)
f[i]=(f[i-1]%3+f[i-2]%3)%3;
int n;
while(~scanf("%d",&n))
{
if(f[n % 8] ==0)
puts("yes");
else
puts("no");
}
return 0;
}

ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!的更多相关文章

  1. zoj 2060 Fibonacci Again(fibonacci数列规律、整除3的数学特性)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2060 题目描述: There are another kind ...

  2. zoj 2723 Semi-Prime(素筛打表+搜索优化)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2723 题目描述: Prime Number Definitio ...

  3. ZOJ 3707 Calculate Prime S 数论

    思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: ...

  4. zoj 2723 Semi-Prime(set)

    Semi-Prime Time Limit: 2 Seconds      Memory Limit: 65536 KB Prime Number Definition An integer grea ...

  5. ZOJ - 3483 - Gaussian Prime

    先上题目: Gaussian Prime Time Limit: 3 Seconds      Memory Limit: 65536 KB In number theory, a Gaussian ...

  6. G - G ZOJ - 2723 (素数打表+set)

    Prime Number Definition An integer greater than one is called a prime number if its only positive di ...

  7. zoj 2723 Semi-Prime

    // 题意都不好理解 我以为是求 一个数被分成2个素数和 然后是求分成2个素数积// 坑爹 忘记写 !=EOF 然后一直超时 然后换了几种 还是超时 一看别人代码 速度明显比我慢// 然后发现被自己坑 ...

  8. ZOJ 2679 Old Bill ||ZOJ 2952 Find All M^N Please 两题水题

    2679:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1679 2952:http://acm.zju.edu.cn/onli ...

  9. ZOJ 3908 Number Game ZOJ Monthly, October 2015 - F

    Number Game Time Limit: 2 Seconds      Memory Limit: 65536 KB The bored Bob is playing a number game ...

随机推荐

  1. NOIP 模拟赛

    NOIP 模拟赛 思路:求 n , m 的 gcd,然后用 n , m 分别除以 gcd:若 n 或 m 为偶数,则输出 1/2. 特别的,当 n = m = 1 时,应输出 1/1 #include ...

  2. 获取cpu使用率

    http://blog.csdn.net/u010515761/article/details/43225621 http://stackoverflow.com/questions/74674/ho ...

  3. 測试password强度

    <html> <!--激情在最后面.请看最后面红色字 这是是个计算password强度的实例 网上有非常多这种样例 只是呢,都不怎么好 这是我写的一个完整的效果,能够通用, new一 ...

  4. 关于app.FragmentManager和v4包的FragmentPagerAdapter冲突

    这几天发现一个问题我用getFragmentManager()得到FragmentManager不能放到FragmentPagerAdapter里面去.由于FragmentPagerAdapter里面 ...

  5. json和XML

    发请求(url) 1.client  ---------------->服务端                发送数据(Json/xml)                      < - ...

  6. button按钮怎么实现超链接

    button按钮怎么实现超链接 一.总结 1.我的按钮实现超链接是通过button内嵌a标签来实现的 <button class="am-btn am-btn-default am-b ...

  7. cmake 常见问题及解决

    1. undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5 未定义对某符号的引用,该错误为链接时(linking)发生的错误.有 ...

  8. 69.类型后缀,重载操作符""

    #include <iostream> using namespace std; class myclass { public: int num; int num2; public: my ...

  9. Looksery Cup 2015 Editorial

    下面是题解,做的不好.下一步的目标是rating涨到 1800,没打过几次cf A. Face Detection Author: Monyura One should iterate through ...

  10. Inversion of Control Containers and the Dependency Injection pattern--Martin Fowler

    原文地址:https://martinfowler.com/articles/injection.html n the Java community there's been a rush of li ...