zoukankan      html  css  js  c++  java
  • code vs1706 求合数和(数论 素数的判定)

    1706 求合数和

     

     时间限制: 1 s
     空间限制: 128000 KB
     题目等级 : 白银 Silver
     
     
    题目描述 Description

    用户输入一个数,然后输出从1开始一直到这个数为止(包括这个数)中所有的合数的和。

    输入描述 Input Description

    一个整数N,0<N<=1000

    输出描述 Output Description

    一行,一个整数,即从1到N中所有合数的和

    样例输入 Sample Input

    样例一:100

    样例二:9

    样例输出 Sample Output

    样例一:3989

    样例二:27

    数据范围及提示 Data Size & Hint

    先找出素数,然后把不是素数的和相加。

    分类标签 Tags 

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath> 
    using namespace std;
    int n,ans;
    bool aa(int x){
        for(int i = 2; i <= sqrt(x); i ++)
            if(x%i==0)    return 1;
        return 0;
    }
    int main(){
        cin>>n;
        for(int i = 4; i <= n; i ++){
            if(aa(i))
            ans+=i;
        }
        cout<<ans;
    }

    思路:简单,不解释;

    细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
  • 相关阅读:
    Lock、Synchronized锁解析
    js多个计时器互不影响触发
    php Excel文件导入 Spreadsheet_Excel_Reader
    Tcp/ip简介
    对称加密和非对称加密
    AFNetworking 3.0迁移指南
    从 Objective-C 里的 Alloc 和 AllocWithZone 谈起
    iOS 沙盒
    SDWebImage解析
    dSYM文件
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/6054226.html
Copyright © 2011-2022 走看看