【数论,水题】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 ...
随机推荐
- JavaScript——以简单的方式理解闭包
闭包,在一开始接触JavaScript的时候就听说过.首先明确一点,它理解起来确实不复杂,而且它也非常好用.那我们去理解闭包之前,要有什么基础呢?我个人认为最重要的便是作用域(lexical scop ...
- picture to string
图片转化为字符原理: 一张m*n大小的图片,实际上可以看成是一个m*n的矩阵.矩阵的每一个元素就是一个Color值,不同的Color值,用不同的Ascii可以在屏幕上打印显示的字符来代替,于是可以得到 ...
- FIREDAC直连ORACLE数据库
UniDac对Oracle的Direct连接,不需要套Oracle客户端dll,deploy时真的时 方便又快捷.FireDac连接Oracle,在没有Oracle Client的情况下,是可以连接上 ...
- HttpMessageConverter用法
HttpMessageConverter接口定义 * Strategy interface that specifies a converter that can convert from and t ...
- 模拟学信网登录,Cookie 序列化,在反序列化之后不能用的问题
昨天和今天在模拟学信网登录,然后抓取用户的信息数据的时候发现一直登录不成功, 登录页面,https://account.chsi.com.cn/passport/login?service=http% ...
- Unity3D之Mecanim动画系统学习笔记(十):Mecanim动画的资源加载相关
资源加载是必备的知识点,这里就说说Mecanim动画的资源如何打包及加载. 注意,Unity4.x和Unity5.x的AssetBundle打包策略不一样,本笔记是基于Unity4.x的AssetBu ...
- 解决iPhone上select时常失去焦点,随意跳到下一个输入框,影响用户操作
window.addEventListener('load', function() { FastClick.attach(document.body); }, false); //300s延迟,解决 ...
- Codeforces Round #185 (Div. 2) C. The Closest Pair 构造
C. The Closest Pair Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/p ...
- Swift常用语法示例代码(二)
此篇文章整理自我以前学习Swift时的一些练习代码,其存在的意义多是可以通过看示例代码更快地回忆Swift的主要语法. 如果你想系统学习Swift或者是Swift的初学者请绕路,感谢Github上Th ...
- iOS开发——图形编程OC篇&OpenGL ES2.0编程步骤
OpenGL ES2.0编程步骤 OpenGL ES (OpenGL for Embedded Systems) 是 OpenGL 三维图形 API 的子集,针对手机.PDA和游戏主机等嵌入式设备而设 ...