题目链接

题意:给出一个数S,求一个最大的数,使这个数所有的因子之和为S;

这个所谓“因子之和”不知道有没有误导性,因为一开始以为得是素数才行。后来复习了下小学数学,比如12的因子分别是1,2,3,4,6,12...

我竟无言以对T^T...

感觉复杂度应该能继续优化的。。没想到好的。。

代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. const int maxn = ;
  8. int vis[maxn], prime[maxn], cnt;
  9. void pre()
  10. {
  11. int m = sqrt(maxn+0.5);
  12. vis[] = ;
  13. vis[] = ;
  14. for(int i = ; i <= m; i++)
  15. if(!vis[i])
  16. for(int j = i*i; j < maxn; j+=i)
  17. vis[j] = ;
  18. cnt = ;
  19. for(int i = ; i < maxn; i++)
  20. if(!vis[i])
  21. prime[cnt++] = i;
  22. }
  23.  
  24. int main()
  25. {
  26. pre();
  27. int S, kase = ;
  28. while(~scanf("%d", &S) && S)
  29. {
  30. if(S == ) {printf("Case %d: 1\n", ++kase); continue;}
  31. bool exist = false;
  32. int i;
  33. for(i = S-; i >= ; i--)
  34. {
  35. // if(!vis[i])
  36. // {
  37. //cout << i << endl;
  38. int sum = ; bool ok = true;
  39. for(int j = ; j <= sqrt(i); j++)
  40. {
  41. int tmp = i/j;
  42. //cout << tmp << endl;
  43. if(sum > S) {ok = false; break;}
  44. if(tmp*j != i) continue;
  45. if(tmp != j) sum += j;
  46. sum += tmp;
  47. }
  48. if(sum == S) {exist = true; break;}
  49. // }
  50. }
  51. if(exist) printf("Case %d: %d\n", ++kase, i);
  52. else printf("Case %d: -1\n", ++kase);
  53.  
  54. }
  55. return ;
  56. }

【数论,水题】UVa 11728 - Alternate Task的更多相关文章

  1. uva 11728 - Alternate Task(数论)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/36409469 option=com_onli ...

  2. UVA 11728 - Alternate Task (数论)

    Uva 11728 - Alternate Task 题目链接 题意:给定一个因子和.求出相应是哪个数字 思路:数字不可能大于因子和,对于每一个数字去算出因子和,然后记录下来就可以 代码: #incl ...

  3. uva 11728 Alternate Task

    vjudge 上题目链接:uva 11728 其实是个数论水题,直接打表就行: #include<cstdio> #include<algorithm> using names ...

  4. UVA 11728 - Alternate Task 数学

    Little Hasan loves to play number games with his friends. One day they were playing a game whereone ...

  5. UVa 11728 Alternate Task (枚举)

    题意:给定一个 n,求一个最大正整数 N 使得 N 的所有正因数和等于 n. 析:对于任何数一个 n,它的所有正因子都是大于等于本身的,因为 n 本身就是自己的正因数,这样的就可以直接暴力了,答案肯定 ...

  6. [ACM_水题] UVA 12502 Three Families [2人干3人的活后分钱,水]

      Three Families  Three families share a garden. They usually clean the garden together at the end o ...

  7. HDU 3215 The first place of 2^n (数论-水题)

    The first place of 2^n Problem Description LMY and YY are mathematics and number theory lovers. They ...

  8. [ACM_水题] UVA 11729 Commando War [不可同时交代任务 可同时执行 最短完成全部时间 贪心]

    There is a war and it doesn't look very promising for your country. Now it's time to act. You have a ...

  9. POJ 1061 青蛙的约会 数论水题

    http://poj.org/problem?id=1061 傻逼题不多说 (x+km) - (y+kn) = dL 求k 令b = n-m ; a = x - y ; 化成模线性方程一般式 : Lx ...

随机推荐

  1. SpringDataMongoDB介绍(二)-MongoOperations介绍

    MongoOperations是一个很强大的接口,有了这个接口,基本上什么都搞定了. 其介绍 Interface that specifies a basic set of MongoDB opera ...

  2. ASP.NET MVC 前端(View)向后端(Controller)中传值

    在MVC中,要把前端View中的值传递给后端Controller, 主要有两种方法 1. 利用Request.Form 或者 Request.QueryString public ActionResu ...

  3. 【Cocos2d-X开发学习笔记】第21期:动画类(CCAnimate)的使用

    本系列学习教程使用的是cocos2d-x-2.1.4(最新版为3.0alpha0-pre) ,PC开发环境Windows7,C++开发环境VS2010 之前我们已经学习过一些方法让节点“动”起来,Co ...

  4. 树莓派加入定时任务实现花生壳定时重启(linux的定时任务)

    由于花生壳在linux下不稳定,联系开机一个星期左右会挂掉,所以要使用定时任务实现每小时刷新一次/启动一次. 使用的是linux下的定时任务crontab去实现. 实现步骤: 1.编辑/etc/cro ...

  5. Myeclipse 10.x 安装Aptana3.2 插件

    安装步骤: 1.下载aptana3.2 Eclipse Plugin插件. 下载地址:http://update1.aptana.org/studio/3.2/024747/index.html 2. ...

  6. mysql和oracle日期和字符相互转换

    一.mysql日期和字符相互转换 1.1.日期——>字符   date_format(date,'%Y-%m-%d')     oracle中的to_char();    1.2.字符——> ...

  7. JS 之如何在插入元素时插在原有元素的前面而不是末尾

    语法: 父级.insertBefore(新元素,被插入的元素):          //在指定的元素前面加入一个新元素 父级.insertBefore(新元素,父级.children[0]); //在 ...

  8. 终于用scons创建了一个MDK工程

    这几天我在学着怎么使用RT-Thread.起初只想用一下里面的RTGUI,却一直没成功,功力实在不行啊. RT-Thread用了scons来创建工程,似乎还能编译,还有很多可配置项,很是方便.于是我想 ...

  9. POJ 3522 Slim Span 最小差值生成树

    Slim Span Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3522 Description Gi ...

  10. Codeforces Round #331 (Div. 2) E. Wilbur and Strings dfs乱搞

    E. Wilbur and Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596 ...