题目 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3856

先预处理求出两个素数的和与积,然后枚举n-prime和n/prime的情况。

表达式可能的情况 a a*b a+b a+b+c a*b*c a*b+c  (注意没有(a+b)*c的情况)

对于a*b和a+b的判重 只需要控制 a<=b的范围即可

对于a*b+c的情况 不存在重复情况

对于a+b+c a*b*c

分三种情况

①a!=b && b!=c 这种情况对于全枚举会出现三次 分别是a+b+c a+c+b b+c+a

②a==b && b!=c 这种情况对于全枚举会出现二次 分别是a+b+c a+c+b

③a==b && b==c  这种情况对于全枚举会出现一次 分别是a+b+c

为了能够去重 可以考虑将②③情况补全成三次 然后sum除了3即可

除以3的求模需要注意不能直接mod,需要模3*mod

130ms 代码,8s的时限太给力了。。

 #include <stdio.h>
#include<math.h>
#include<string.h>
#define bigt long long
#define N 80005
const int M=;
int a[N],p[N];
int pp[N]={};
int pp2[N]={};
int pnum;
bigt sum =;
bigt sum1 =;
bigt sum2 = ;
const bigt mod = 3000000021LL;
const int mod2 = ;
void Prime() {
int i, j;
memset(a, , N*sizeof(a[]));
pnum = ;
for(i = ; i < N; ++i) {
if(!a[i]) a[i] = p[pnum++] = i;
for(j = ; j < pnum && i * p[j] < N; ++j) {
a[i*p[j]] = p[j];
if(!(i%p[j])) break;
}
}
} void init()
{
int i=,j;
do{
for(j=i;j<pnum;j++)
{
if(p[i]+p[j]>M)
break;
else
{
pp[p[i]+p[j]] ++;
}
}
if(p[i]<=sqrt(M*1.0))
for(j=i;j<pnum;j++)
{
if(p[i]*p[j]>M)
break;
else
{
pp2[p[i]*p[j]] ++;
}
}
i++;
}while(i<pnum);
} int main()
{
int n;
Prime();
init();
while(scanf("%d",&n)!=EOF)
{
sum = sum1 = sum2 = ;
if(a[n]==n) sum2++; for(int i=;p[i]<n;i++)
{
int st = p[i];
int ed = n - p[i];
if(ed%== && a[ed/]==ed/)
{
sum1++;
if(ed/==st)
sum1++;
} sum1 = sum1 + pp[ed];
sum2 = sum2 + pp2[ed]; if(a[ed]==ed && *st<=n) sum2++;
if(sum1>mod) sum1 -= mod;
if(sum2>mod2) sum2 -= mod2;
} sum = (sum1/ + sum2 )%mod2;
sum1=sum2=; for(int i=;p[i]<n-;i++)
{
if(!(n%p[i]))
{
int st = p[i];
int ed = n / p[i];
double tmp = sqrt(ed)+1e-;
int tmp2 = (int)tmp; if(tmp2*tmp2==ed && a[tmp2]==tmp2)
{
sum1++;
if(tmp2==st)
sum1++;
} sum1 = (sum1 + pp2[ed]);
if(a[ed]==ed && st*st<=n)
sum2++; if(sum1>mod)
sum1 -= mod;
}
}
sum = sum + (sum1/ + sum2 )%mod2;
printf("%lld\n",sum%mod2);
}
return ;
}

2013 acm 长沙网络赛 G题 素数+枚举 Goldbach的更多相关文章

  1. 2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)

    Hypersphere Time Limit: 1 Second       Memory Limit: 32768 KB In the world of k-dimension, there's a ...

  2. 2013 ACM/ICPC 长沙网络赛J题

    题意:一个数列,给出这个数列中的某些位置的数,给出所有相邻的三个数字的和,数列头和尾处给出相邻两个数字的和.有若干次询问,每次问某一位置的数字的最大值. 分析:设数列为a1-an.首先通过相邻三个数字 ...

  3. 2013 长沙网络赛J题

    思路:这题对于其他能退出所有值的情况比较好像,唯一不能确定的是XXOXXOXXOXX这个形式的序列,其中XX表示未知,O表示已知. 我们令num[1]=0,那么num[4]=sum[3]-sum[2] ...

  4. 2013 长沙网络赛 B 题 Bizarre Routine

    题解 http://blog.csdn.net/u010257508/article/details/11936129 #include <iostream> #include <c ...

  5. 2016 acm香港网络赛 A题. A+B Problem (FFT)

    原题地址:https://open.kattis.com/problems/aplusb FFT代码参考kuangbin的博客:http://www.cnblogs.com/kuangbin/arch ...

  6. 2018 ACM-ICPC徐州站网络赛 G题

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xxx , yy ...

  7. 2015北京网络赛 G题 Boxes bfs

    Boxes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc2015beijingonl ...

  8. 2016 acm香港网络赛 C题. Classrooms(贪心)

    原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...

  9. 2016 acm香港网络赛 F题. Crazy Driver(水题)

    原题网址:https://open.kattis.com/problems/driver Crazy Driver In the Linear City, there are N gates arra ...

随机推荐

  1. android 程序代码执行adb

    Runtime.getRuntime().exec("adb pull /dev/graphics/fb0 C:/fb1"); Runtime. getRuntime().exec ...

  2. Spark Streaming源码解读之Driver中ReceiverTracker架构设计以具体实现彻底研究

    本期内容 : ReceiverTracker的架构设计 消息循环系统 ReceiverTracker具体实现 一. ReceiverTracker的架构设计 1. ReceiverTracker可以以 ...

  3. MVC KindEdit

    先将下载的KindEditor放到项目中 View页面 <!DOCTYPE html><html><head>    <meta name="vie ...

  4. 原生js事件和jquery事件的执行顺序问题

    场景:近日,写前端页面时候,在针对输入框input操作时,用到了jquery的插件,插件中使用了jquery的focus()和blur()方法.但是同时,又需要在插件之外再针对输入框的获取焦点和失去焦 ...

  5. cs11_c++_lab7

    wcount.cc #include <iostream> #include <map> #include <string> #include <algori ...

  6. AC 设置DMZ口上网

  7. rabbitMQ学习(一)

    一般模式 服务端: import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabb ...

  8. CountDownLatch如何使用

    正如每个Java文档所描述的那样,CountDownLatch是一个同步工具类,它允许一个或多个线程一直等待,直到其他线程的操作执行完后再执行.在Java并发中,countdownlatch的概念是一 ...

  9. Jquery--动画

    动画: 1.show(),hide() 2..stop() .slideDown();  向下. .stop().slideUp();  向上 (可以做下拉)        .stop() 执行之前加 ...

  10. linux 学习15 16 启动管理,备份和恢复

    第十五讲 启动管理 . CentOS .x 启动管理 //此处指6.3 系统运行级别 .运行级别 运行级别 含 义 关机 单用户模式,可以想象为windows的安全模式,主要用于系统修复 //linu ...