题意:给定一个 n,求一个最大正整数 N 使得 N 的所有正因数和等于 n。

析:对于任何数一个 n,它的所有正因子都是大于等于本身的,因为 n 本身就是自己的正因数,这样的就可以直接暴力了,答案肯定是在 1 ~ n 范围内。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define be begin()
#define ed end()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define aLL 1,n,1
#define FOR(i,n,x) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.in", "r", stdin)
#define freopenw freopen("out.out", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int maxn = 1000 + 20;
const int maxm = 76543;
const int mod = 1e9 + 9;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
}
inline int readInt(){ int x; scanf("%d", &x); return x; } int ans[maxn]; int main(){
ms(ans, -1);
for(int i = 1; i <= 1000; ++i){
int t = sqrt(i + 1.);
int sum = 0;
for(int j = 1; j < t; ++j) if(i % j == 0)
sum += j + i / j;
if(i % t == 0){
sum += t;
if(t != i / t) sum += i / t;
}
if(sum < maxn) ans[sum] = i;
}
int kase = 0;
while(scanf("%d", &n) == 1 && n)
printf("Case %d: %d\n", ++kase, ans[n]);
return 0;
}

  

UVa 11728 Alternate Task (枚举)的更多相关文章

  1. uva 11728 - Alternate Task(数论)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/36409469 option=com_onli ...

  2. UVA 11728 - Alternate Task (数论)

    Uva 11728 - Alternate Task 题目链接 题意:给定一个因子和.求出相应是哪个数字 思路:数字不可能大于因子和,对于每一个数字去算出因子和,然后记录下来就可以 代码: #incl ...

  3. uva 11728 Alternate Task

    vjudge 上题目链接:uva 11728 其实是个数论水题,直接打表就行: #include<cstdio> #include<algorithm> using names ...

  4. UVA 11728 - Alternate Task 数学

    Little Hasan loves to play number games with his friends. One day they were playing a game whereone ...

  5. 【数论,水题】UVa 11728 - Alternate Task

    题目链接 题意:给出一个数S,求一个最大的数,使这个数所有的因子之和为S; 这个所谓“因子之和”不知道有没有误导性,因为一开始以为得是素数才行.后来复习了下小学数学,比如12的因子分别是1,2,3,4 ...

  6. Alternate Task UVA - 11728 (暴力。。分解质因子)

    题意: 输入一个正整数S,(S  <= 1000)求一个最大的正整数N,使得N的所有正因子之和为S. 解析: ..求1000以内的所有数的正因子和 ...输出.. #include <io ...

  7. UVa 10465 Homer Simpson (枚举)

    10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

  8. UVA 1262 Password 暴力枚举

    Password Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID:  ...

  9. UVA 12169 Disgruntled Judge 枚举+扩展欧几里得

    题目大意:有3个整数 x[1], a, b 满足递推式x[i]=(a*x[i-1]+b)mod 10001.由这个递推式计算出了长度为2T的数列,现在要求输入x[1],x[3],......x[2T- ...

随机推荐

  1. 未预期的符号 `$'{\r'' 附近有语法错误

    ../runcmake: 行 2: $'\r': 未找到命令 ../runcmake: 行 3: 未预期的符号 `$'{\r'' 附近有语法错误 考虑到代码是从windows下一直过来的,脚本可能在格 ...

  2. 关于h5使用bpmn.js

    bpmn.js网站地址:https://bpmn.io/toolkit/bpmn-js/ bpmnjs是一款工作流绘制框架,遵循了bpmn2.0规范,实现从前台绘制工作流到后台执行的效果. 图示: 但 ...

  3. 关于wordpress中的contact form7和WP Mail SMTP的一些设置

    昨天帮客户解决了这个问题  折腾了好几个小时  下面说下流程 先配置的  wp mail smtp 如果配置完毕后  就可以使用里面配置的邮件   放到contact form7 中的 发件人中 1 ...

  4. yarn 报错 requested virtual cores < 0, or requested virtual cores > max configured, requestedVirtualCores=6, maxVirtualCores=4 原因

    INFO ApplicationMaster:54 - Final app status: FAILED, exitCode: 13, (reason: Uncaught exception: org ...

  5. C# Excel添加超链接

    操作当前单元格(关键代码就两行) Range range = (Range)ExSheet.Cells[i + 2, j + 1];                                   ...

  6. 深度学习原理与框架-Tensorboard可视化展示(代码) 1.tf.reuse_default_graph(进行结构图的重置) 2.tf.summary.FileWriter(writer实例化) 3. write.add_graph(graph的写入) 4. tf.summary.merge_all(将summary进行合并) 5.write.add_summary(将所有summary)

    1. tf.reuse_default_graph() # 对graph结构图进行清除和重置操作 2.tf.summary.FileWriter(path)构造writer实例化,以便进行后续的gra ...

  7. 为Firefox浏览器安装Firebug插件

    一.确保联网 二.打开Firefox 三.菜单:工具 -> 附加组件 显示附加组件管理器界面,点扩展 在搜索框输入firebug,搜,在搜索结果列表中找到Firebug项,安装 安装进度 安装完 ...

  8. docker报错

    用docker搭建环境时可能会遇到错误:No releases available for package "xxxx" No releases available for pac ...

  9. 安全运维之:Linux后门入侵检测工具的使用

    安全运维之:Linux后门入侵检测工具的使用 https://blog.csdn.net/exitgogo/article/details/39547113

  10. 556. Next Greater Element III下一个更大的数字

    [抄题]: Given a positive 32-bit integer n, you need to find the smallest 32-bit integer which has exac ...