【数论,水题】UVa 11728 - Alternate Task
题意:给出一个数S,求一个最大的数,使这个数所有的因子之和为S;
这个所谓“因子之和”不知道有没有误导性,因为一开始以为得是素数才行。后来复习了下小学数学,比如12的因子分别是1,2,3,4,6,12...
我竟无言以对T^T...
感觉复杂度应该能继续优化的。。没想到好的。。
代码:
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- #include<cmath>
- using namespace std;
- const int maxn = ;
- int vis[maxn], prime[maxn], cnt;
- void pre()
- {
- int m = sqrt(maxn+0.5);
- vis[] = ;
- vis[] = ;
- for(int i = ; i <= m; i++)
- if(!vis[i])
- for(int j = i*i; j < maxn; j+=i)
- vis[j] = ;
- cnt = ;
- for(int i = ; i < maxn; i++)
- if(!vis[i])
- prime[cnt++] = i;
- }
- int main()
- {
- pre();
- int S, kase = ;
- while(~scanf("%d", &S) && S)
- {
- if(S == ) {printf("Case %d: 1\n", ++kase); continue;}
- bool exist = false;
- int i;
- for(i = S-; i >= ; i--)
- {
- // if(!vis[i])
- // {
- //cout << i << endl;
- int sum = ; bool ok = true;
- for(int j = ; j <= sqrt(i); j++)
- {
- int tmp = i/j;
- //cout << tmp << endl;
- if(sum > S) {ok = false; break;}
- if(tmp*j != i) continue;
- if(tmp != j) sum += j;
- sum += tmp;
- }
- if(sum == S) {exist = true; break;}
- // }
- }
- if(exist) printf("Case %d: %d\n", ++kase, i);
- else printf("Case %d: -1\n", ++kase);
- }
- return ;
- }
【数论,水题】UVa 11728 - Alternate Task的更多相关文章
- uva 11728 - Alternate Task(数论)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/36409469 option=com_onli ...
- UVA 11728 - Alternate Task (数论)
Uva 11728 - Alternate Task 题目链接 题意:给定一个因子和.求出相应是哪个数字 思路:数字不可能大于因子和,对于每一个数字去算出因子和,然后记录下来就可以 代码: #incl ...
- uva 11728 Alternate Task
vjudge 上题目链接:uva 11728 其实是个数论水题,直接打表就行: #include<cstdio> #include<algorithm> using names ...
- UVA 11728 - Alternate Task 数学
Little Hasan loves to play number games with his friends. One day they were playing a game whereone ...
- UVa 11728 Alternate Task (枚举)
题意:给定一个 n,求一个最大正整数 N 使得 N 的所有正因数和等于 n. 析:对于任何数一个 n,它的所有正因子都是大于等于本身的,因为 n 本身就是自己的正因数,这样的就可以直接暴力了,答案肯定 ...
- [ACM_水题] UVA 12502 Three Families [2人干3人的活后分钱,水]
Three Families Three families share a garden. They usually clean the garden together at the end o ...
- 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 ...
- [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 ...
- POJ 1061 青蛙的约会 数论水题
http://poj.org/problem?id=1061 傻逼题不多说 (x+km) - (y+kn) = dL 求k 令b = n-m ; a = x - y ; 化成模线性方程一般式 : Lx ...
随机推荐
- SpringDataMongoDB介绍(二)-MongoOperations介绍
MongoOperations是一个很强大的接口,有了这个接口,基本上什么都搞定了. 其介绍 Interface that specifies a basic set of MongoDB opera ...
- ASP.NET MVC 前端(View)向后端(Controller)中传值
在MVC中,要把前端View中的值传递给后端Controller, 主要有两种方法 1. 利用Request.Form 或者 Request.QueryString public ActionResu ...
- 【Cocos2d-X开发学习笔记】第21期:动画类(CCAnimate)的使用
本系列学习教程使用的是cocos2d-x-2.1.4(最新版为3.0alpha0-pre) ,PC开发环境Windows7,C++开发环境VS2010 之前我们已经学习过一些方法让节点“动”起来,Co ...
- 树莓派加入定时任务实现花生壳定时重启(linux的定时任务)
由于花生壳在linux下不稳定,联系开机一个星期左右会挂掉,所以要使用定时任务实现每小时刷新一次/启动一次. 使用的是linux下的定时任务crontab去实现. 实现步骤: 1.编辑/etc/cro ...
- Myeclipse 10.x 安装Aptana3.2 插件
安装步骤: 1.下载aptana3.2 Eclipse Plugin插件. 下载地址:http://update1.aptana.org/studio/3.2/024747/index.html 2. ...
- mysql和oracle日期和字符相互转换
一.mysql日期和字符相互转换 1.1.日期——>字符 date_format(date,'%Y-%m-%d') oracle中的to_char(); 1.2.字符——> ...
- JS 之如何在插入元素时插在原有元素的前面而不是末尾
语法: 父级.insertBefore(新元素,被插入的元素): //在指定的元素前面加入一个新元素 父级.insertBefore(新元素,父级.children[0]); //在 ...
- 终于用scons创建了一个MDK工程
这几天我在学着怎么使用RT-Thread.起初只想用一下里面的RTGUI,却一直没成功,功力实在不行啊. RT-Thread用了scons来创建工程,似乎还能编译,还有很多可配置项,很是方便.于是我想 ...
- POJ 3522 Slim Span 最小差值生成树
Slim Span Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3522 Description Gi ...
- 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 ...