zoukankan      html  css  js  c++  java
  • LightOJ1259 Goldbach`s Conjecture

    题面

    T组询问,每组询问是一个偶数n
    验证哥德巴赫猜想
    回答n=a+b
    且a,b(a<=b)是质数的方案个数

    Input

    Input starts with an integer T (≤ 300), denoting the number of test cases.
    Each case starts with a line containing an integer n (4 ≤ n ≤ 107, n is even).

    Sol

    垃圾题,枚举质数就好

    # include <bits/stdc++.h>
    # define RG register
    # define IL inline
    # define Fill(a, b) memset(a, b, sizeof(a))
    using namespace std;
    typedef long long ll;
    const int __(1e7 + 10);
    
    IL ll Read(){
    	char c = '%'; ll x = 0, z = 1;
    	for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
    	for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
    	return x * z;
    }
    
    int prime[__ / 10], num, n, ans;
    bool isprime[__];
    
    IL void Prepare(){
    	isprime[1] = 1;
    	for(RG int i = 2; i <= __; ++i){
    		if(!isprime[i]) prime[++num] = i;
    		for(RG int j = 1; j <= num && i * prime[j] <= __; ++j){
    			isprime[i * prime[j]] = 1;
    			if(!(i % prime[j])) break;
    		}
    	}
    }
    
    int main(RG int argc, RG char *argv[]){
    	Prepare();
    	for(RG int T = Read(), Case = 1; Case <= T; ++Case){
    		n = Read(); ans = 0;
    		for(RG int i = 1; i <= num && prime[i] + prime[i] <= n; ++i) ans += !isprime[n - prime[i]];
    		printf("Case %d: %d
    ", Case, ans);
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    js对象深拷贝
    数组去重
    css布局之双飞翼布局
    css布局之圣杯布局
    在浏览器中输入URL并回车后都发生了什么?
    浮动和清除浮动
    Javascript 构造函数模式、原型模式
    Javascript之对象组合继承
    js可以随意拖拽的div的实现
    博客美化 之博客的魔方效果
  • 原文地址:https://www.cnblogs.com/cjoieryl/p/8250447.html
Copyright © 2011-2022 走看看