【数论,水题】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 ...
随机推荐
- 【转】关于Xcode的Other Linker Flags
链接器 首先,要说明一下Other Linker Flags到底是用来干嘛的.说白了,就是ld命令除了默认参数外的其他参数.ld命令实现的是链接器的工作,详细说明可以在终端man ld查看. 如果有人 ...
- [iOS 多线程 & 网络 - 1.2] - 多线程GCD
A.GCD基本使用 1.GCD的概念 什么是GCD全称是Grand Central Dispatch,可译为"牛逼的中枢调度器"纯C语言,提供了非常多强大的函数GCD的优势GCD是 ...
- jQuery基础学习7——层次选择器find()方法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- HDU 2045 不容易系列之(3)—— LELE的RPG难题 (递推)
题意:略. 析:首先是假设前n-2个已经放好了,那么放第 n 个时,先考虑一下第 n-1 放的是什么,那么有两种情况. 如果n-1放的是和第1个一样的,那么第 n 个就可以在n-2的基础上放2个,也就 ...
- CodeForces 548A Mike and Fax (回文,水题)
题意:给定一个字符串,问是不是恰好存在 k 个字符串是回文串,并且一样长. 析:没什么好说的,每次截取n/k个,判断是不是回文就好. 代码如下: #include<bits/stdc++.h&g ...
- TinyTask Portable(录制和回放电脑操作过程)
一直想找个软件,可以回放自己或他人编码的过程.我认为,只有亲眼看到别人是怎么做的,才能更好的了解他人的思路. 虽然找到http://thecodeplayer.com/这个,但它只能回放它上面的代码, ...
- OpenNebula Restfull 接口请求示例
Fri Jun 20 07:28:20 2014 [I]: 10.0.2.2 - - [20/Jun/2014 07:28:20] "POST /vmtemplate HTTP/1.1&qu ...
- hibernate AOP
摘自:http://pandonix.iteye.com/blog/336873/ 此前对于AOP的使用仅限于声明式事务,除此之外在实际开发中也没有遇到过与之相关的问题.最近项目中遇到了以下几点需求, ...
- 更新插件时提示“正在更新缓存”“正在等待jockey-backend退出”
Ubuntu 11 更新语言插件, 更新时 提示正在更新缓存”“正在等待jockey-backend退出”,然后就不动了. 解决方案: 在终端中键入ps -e | grep jockey 系统会显示一 ...
- SAP-设置显示表格格式
在我们用SAP系统的过程中产看表格的时候,需要设置查看表格的格式,表格的格式主要包含两个方面: 1,表格的样式 在查看表格的时候点击[设置]-[用户参数] 勾选[ALV Grid display]就控 ...