zoukankan      html  css  js  c++  java
  • hduoj 1286 找新朋友

    http://acm.hdu.edu.cn/showproblem.php?pid=1286

    找新朋友

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 8694    Accepted Submission(s): 4592


    Problem Description
    新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。
     
    Input
    第一行是测试数据的组数CN(Case number,1<CN<10000),接着有CN行正整数N(1<n<32768),表示会员人数。
     
    Output
    对于每一个N,输出一行新朋友的人数,这样共有CN行输出。
     
    Sample Input
     
    2
    25608
    24027
     
    Sample Output
     
    7680
    16016
     

    分析:

    题目要求找出小于n 的所有的与n互素的整数(包括1 不包括n)。

    筛法求素数orz

    AC代码:

     1 #include<stdio.h>
     2 #include<string.h>
     3 int judge[40000];
     4 int main()
     5 {
     6     int n, m;
     7     int ans;
     8     scanf("%d", &n);
     9     while(n--)
    10         {
    11         int cnt = 0;
    12         scanf("%d", &m);
    13         memset(judge, 0, sizeof(judge));
    14         for(int i = 2; i <= m / 2; i++)
    15         {
    16             if(m%i == 0)
    17             {
    18                 judge[i] = 1;
    19                 for(int j = i; j <= m; j+=i)
    20                     judge[j] = 1;
    21             }
    22         }
    23         for(int i = 2; i < m; i++){
    24             if(judge[i] == 0){
    25                 cnt++;
    26             }
    27         }
    28         printf("%d
    ", cnt + 1);
    29     }
    30     
    31     return 0;
    32 }    
  • 相关阅读:
    视频质量诊断之详解
    Leetcode 22.生成括号对数
    leetcode 19.删除链表的第n个节点
    Leetcode 11.盛最多水的容器
    Leetcode 6.Z字形变换
    Leetcode 4.两个排序数组的中位数
    Leetcode 3.无重复字符的最长子串
    Leetcode 1.两数之和
    RNN and Language modeling in TensorFlow
    Tensorflow word2vec+manage experiments
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4477567.html
Copyright © 2011-2022 走看看