【数论,水题】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 ...
随机推荐
- [iOS基础控件 - 6.9.1] 聊天界面Demo 代码
框架: 所有代码文件: Model: // // Message.h // QQChatDemo // // Created by hellovoidworld on 14/12/8. // ...
- CSS3之背景剪裁Background-clip
CSS3之背景剪裁Background-clip是CSS3中新添加的内容.这个属性还是比较简单的,主要分五个属性值:border.padding.content.no-clip和text.下面将针对这 ...
- 12 为何使用Html5+CSS3
一:大多浏览器支持,低版本也没问题 我看点这方面的资料,是为了做手机应用网站(有三个方案,这个是备用方案),可以开发响应式网站,可以脱离开发平台进行跨平台. 在Html5网页中引入Modernizr, ...
- 如何开发原生的 JavaScript 插件(知识点+写法)
一.前言 通过 "WWW" 原则我们来了解 JavaScript 插件这个东西 第一个 W "What" -- 是什么?什么是插件,我就不照搬书本上的抽象概念了 ...
- CSS 背景图片的定位和缩放
在 CSS 中,利用 background-image 属性我们可以指定元素的背景图片,例如: .example { background-image: url(image/some.png); ba ...
- 教你50招提升ASP.NET性能(十八):在处理网站性能问题前,首先验证问题是否出在客户端
(29)Before tackling any website performance issue, first verify the problem isn’t on the client 招数29 ...
- html 前台通用表单
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- c# winform 把彩色图片转换为灰色的图片,变灰,灰度图片,速度很快,safe,unsafe
把彩色图片转换为灰色的图片,直接用.net接口遍历每个像素点转换的效率非常低,800K的图片65万像素我的电脑要用5分钟,而用了unsafe,速度提高了几千倍,同样的图片只用了0.几秒 附一个常用的遍 ...
- SpringMVC经典系列-14自己定义SpringMVC的拦截器---【LinusZhu】
注意:此文章是个人原创.希望有转载须要的朋友们标明文章出处.假设各位朋友们认为写的还好,就给个赞哈.你的鼓舞是我创作的最大动力,LinusZhu在此表示十分感谢,当然文章中如有纰漏,请联系linusz ...
- C/C++学习站点资源
学习论坛: 轩辕软件论坛 中国IT实验室C/C++论坛 编程爱好者论坛 编程中国论坛 进阶站点: 浙江工业 http://acm.zjut.edu.cn 浙江大学 http://acm.zju.edu ...