| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2869 人关注过本帖
标题:唉,杭电ACM一道很坑爹的题目,素因子什么的,大侠快进来看卡,帮助帮助,我 ...
取消只看楼主 加入收藏
skyn
Rank: 2
来 自:西南交通大学
等 级:论坛游民
帖 子:24
专家分:32
注 册:2011-10-17
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:2 
唉,杭电ACM一道很坑爹的题目,素因子什么的,大侠快进来看卡,帮助帮助,我要纠结得吐血身亡了!!(已加我的思路注释,先谢谢了!!在线等。。在线等)
程序代码:
#include <stdio.h>
#include<math.h>
void main()
{
    int i[5000],j,b,d,a,c[5000],n,m,k,im,e,em,p; ////这里很混乱。。。
    k=0;
    scanf("%d",&n);
    for(m=0;m<n;m++)////输入n个数
    {
   
   
    scanf("%d",&i[m]);
    im=i[m];
        for(;im>=2;im--) ///先找到这个数里的素数
    {
           
   for(j=2;j<=sqrt(im);j++)
     {
      b=im%j;
     if(b==0)
     {
      break;
      }
     }
     if((b!=0)&&(i[m]%im==0)&&(i[m]!=im)) ///再判断这个素数是不是他的因子
      {
         
          c[m]=im; ////记录素因子
           
           // printf("%d",c[m]); ///用来测试用的
             
            break;
         
    
      }
   
   
    }
    }

   
    d=c[0];
    for(j=0;j<=m;j++) ////判断哪一个素因子最大
    {
        if(d<=c[j])
        {
        d=c[j];
        e=j;
        }
    }
    printf("\n%d",i[e]); ///输出。。。跟例子一样的,就是WA。。
    return 0;
   
}
题目在这找到了一个有翻译的。

题目号是杭电2710

Description

To improve the organization of his farm, Farmer John labels each of his N (1 <= N <= 5,000) cows with a distinct serial number in the range 1..20,000. Unfortunately, he is unaware that the cows interpret some serial numbers as better than others. In particular, a cow whose serial number has the highest prime factor enjoys the highest social standing among all the other cows.

(Recall that a prime number is just a number that has no divisors except for 1 and itself. The number 7 is prime while the number 6, being divisible by 2 and 3, is not).

Given a set of N (1 <= N <= 5,000) serial numbers in the range 1..20,000, determine the one that has the largest prime factor.

/*
约翰的农场开始渐入正轨了,因为他给每头牛贴上了范围在1..20,000的清晰的序列号标签。不幸地,他不知道牛认为有一些序列号比较好。一只牛的序列号如果有比其它牛都高的素因子,那它就有最高的社会地位。

(回忆一下,素数指它只有1和本身两个约数。数字7是素数而6不是,因为6还有约数2和3)。

给你N(1 <= N <= 5,000)个序列号,每个序列号的范围在 1..20,000,确定谁有最大的素因子。
*/

Input

* Line 1: A single integer, N

* Lines 2..N+1: The serial numbers to be tested, one per line

/*
* 第 1 行:一个单独的整数 N。
* 第 2-N+1 行:N个序列号,每行1个。
*/

Output

* Line 1: The integer with the largest prime factor. If there are more than one, output the one that appears earliest in the input file.

/*
一行:具有最大素因子的序列号。如果有多个这样的序列号,则输出输入数据中较早输入的数。
*/

Sample Input


4
36
38
40
42

Sample Output


38

Hint

OUTPUT DETAILS:
19 is a prime factor of 38. No other input number has a larger prime factor.

/*
输出解释:
19是38的最大的素因子。其它没有哪个数有比它更大的素因子了。
*/



[ 本帖最后由 skyn 于 2012-8-20 20:52 编辑 ]
搜索更多相关主题的帖子: 在线 
2012-08-20 20:31
skyn
Rank: 2
来 自:西南交通大学
等 级:论坛游民
帖 子:24
专家分:32
注 册:2011-10-17
收藏
得分:0 
大神。大侠!!快来救救我、、、我纠结这道题 都快要吐血身亡了!!

﹎'ひS.т.й.R.S.に`"
2012-08-20 20:40
skyn
Rank: 2
来 自:西南交通大学
等 级:论坛游民
帖 子:24
专家分:32
注 册:2011-10-17
收藏
得分:0 
回复 3楼 草狼
越界?没有超出范围呀,


关于多次输入。。换成个while(scanf("%d",&n))!=EOF)试试

﹎'ひS.т.й.R.S.に`"
2012-08-20 21:27
快速回复:唉,杭电ACM一道很坑爹的题目,素因子什么的,大侠快进来看卡,帮助帮 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019338 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved