【数论,水题】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 ...
随机推荐
- Struts2的运行流程以及关键拦截器介绍
Struts2的运行流程 1.ActionProxy是Action的一个代理类,也就是说Action的调用是通过ActionProxy实现的,其实就是调用了ActionProxy.execute()方 ...
- 【转】iOS可执行文件瘦身方法
http://blog.cnbang.net/tech/2544/ 缩减iOS安装包大小是很多中大型APP都要做的事,一般首先会对资源文件下手,压缩图片/音频,去除不必要的资源.这些资源优化做完后,我 ...
- HDU 5821 Ball (贪心)
Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...
- Gradle – Spring 4 MVC Hello World Example
In this tutorial, we will show you a Gradle + Spring 4 MVC, Hello World Example (JSP view), XML conf ...
- SOP、DIP、PLCC、TQFP、PQFP、TSOP、BGA封装解释
1. SOP封装SOP是英文Small Outline Package的缩写,即小外形封装.SOP封装技术由1968-1969年菲利浦公司开发成功,以后逐渐派生出SOJ(J型引脚小外形封装).TSOP ...
- ASP.NET项目中引用全局dll
在ASP.NET项目中,有些dll是全局dll,也就是说,没有放在单个项目的引用中.它们一般存放在如下目录C:\Windows\assembly中 这个时候,我们需要在单个项目中引用他们,应该如何做呢 ...
- HDU 5768 Lucky7 (中国剩余定理+容斥)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5768 给你n个同余方程组,然后给你l,r,问你l,r中有多少数%7=0且%ai != bi. 比较明显 ...
- 初学Android 二 创建项目以及目录结构
命令行创建 android create project Usage: android [global options] create project [action options] Global ...
- 安卓任意两个或多个Fragment之间的交互与刷新界面
平时项目中遇到一个问题:在子fragment中刷新父fragment的界面,通俗的说也就是在任何一个fragment中来刷新另一个fragment.大家都知道activity和fragment之间的交 ...
- Ehcache(01)——简介、基本操作
http://haohaoxuexi.iteye.com/blog/2112170 目录 1 CacheManager 1.1 构造方法构建 1.2 静态方法构建 2 ...