UVA 11728 - Alternate Task 数学
Little Hasan loves to play number games with his friends. One day they were playing a game where
one of them will speak out a positive number and the others have to tell the sum of its factors. The
first one to say it correctly wins. After a while they got bored and wanted to try out a different game.
Hassan then suggested about trying the reverse. That is, given a positive number S, they have to find
a number whose factors add up to S. Realizing that this task is tougher than the original task, Hasan
came to you for help. Luckily Hasan owns a portable programmable device and you have decided to
burn a program to this device. Given the value of S as input to the program, it will output a number
whose sum of factors equal to S.
Input
Each case of input will consist of a positive integer S ≤ 1000. The last case is followed by a value of
‘0’.
Output
For each case of input, there will be one line of output. It will be a positive integer whose sum of
factors is equal to S. If there is more than one such integer, output the largest. If no such number
exists, output ‘-1’. Adhere to the format shown in sample output.
Sample Input
1
102
1000
0
Sample Output
Case 1: 1
Case 2: 101
Case 3: -1
题意: 给你一个S, 问你n的因子数的和 为S ,求n
题解 : S很小,求出 n的因子和 S, 数组取反就好了
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long ll; const int N=; int a[N + ], b[N + ];
void init() {
memset(a,-,sizeof(a));
for(int i = ; i <= N; i++) {
for(int j = i; j <= N; j += i) {
b[j] += i;
}
if(b[i] < N) a[b[i]] = i;
}
}
int main() {
init();
int cas = , n;
while(~scanf("%d",&n)) {
if(n == ) break;
printf("Case %d: %d\n", cas++, a[n]);
}
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
题目链接 题意:给出一个数S,求一个最大的数,使这个数所有的因子之和为S; 这个所谓“因子之和”不知道有没有误导性,因为一开始以为得是素数才行.后来复习了下小学数学,比如12的因子分别是1,2,3,4 ...
- UVa 11728 Alternate Task (枚举)
题意:给定一个 n,求一个最大正整数 N 使得 N 的所有正因数和等于 n. 析:对于任何数一个 n,它的所有正因子都是大于等于本身的,因为 n 本身就是自己的正因数,这样的就可以直接暴力了,答案肯定 ...
- Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task 数学 mod运算的性质
C. Ehab and a 2-operation task 数学 mod运算的性质 题意: 有两种对前缀的运算 1.对前缀每一个\(a +x\) 2.对前缀每一个\(a\mod(x)\) 其中x任选 ...
- woj1010 alternate sum 数学 woj1011 Finding Teamates 数学
title: woj1010 alternate sum 数学 date: 2020-03-10 categories: acm tags: [acm,woj,数学] 一道数学题.简单. 题意 给一个 ...
- Alternate Task UVA - 11728 (暴力。。分解质因子)
题意: 输入一个正整数S,(S <= 1000)求一个最大的正整数N,使得N的所有正因子之和为S. 解析: ..求1000以内的所有数的正因子和 ...输出.. #include <io ...
- UVa 1639 - Candy(数学期望 + 精度处理)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- [Algorithm]扔杯问题
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Netty简单介绍(非原创)
文章大纲 一.Netty基础介绍二.Netty代码实战三.项目源码下载四.参考文章 一.Netty基础介绍 1. 简介 官方定义为:”Netty 是一款异步的事件驱动的网络应用程序框架,支持快速地 ...
- 二次排序问题(分别使用Hadoop和Spark实现)
不多说,直接上干货! 这篇博客里的算法部分的内容来自<数据算法:Hadoop/Spark大数据处理技巧>一书,不过书中的代码虽然思路正确,但是代码不完整,并且只有java部分的编程,我在它 ...
- 关于原生app、webApp、混合app的介绍
WebApp 原生App(Native App) 混合App(hybrid App) webApp: 用html5,css3 js开发的网页,运行在移动端的浏览器 zepto.angular.vue. ...
- houxiurong.com 关于Tomcat7部署 一台机器部署两个项目,一个用域名访问,一个用IP访问
该内容来自 http://houxiurong.com,转载请说明出处. 1.使用IP访问的项目放在Tomcat7 的webapps目录下面:比如:AAA 2.使用域名访问的项目放在Tomcat7的w ...
- undefined reference to “boost” in Qt—Ubuntu
一:使用PCL时遇到的问题 原因:缺少boost的lib包含: 在Pro文件里面添加: LIBS += -lboost_system .....................等库文件包含 二:编译B ...
- max 宏定义取消:error C2589: error C2059: 语法错误 : “::”
原文链接:http://blog.csdn.net/danelumax2/article/details/9172465有修改! 一:关于Pcl和WIndef的冲突: 1. 错误输出 ./zlibra ...
- C++:数据流和缓冲区
(1):C++之自定义的input缓冲区 原文链接:http://hi.baidu.com/nicker2010/item/d0c4cd2a7caf27c4ddf69aeb input stream用 ...
- 【技术累积】【点】【java】【2】聊一聊似曾相识的switch语句
闲聊 有些东西并不能像爱因斯坦老先生说的那样,书上查的到就不用去记住... 开始 java使用了C的所有流程控制语句: java中同样有switch语句: 大多数情况下,switch都可以用if替换: ...
- getopt函数
getopt -- 解析命令的可选项 [说明]getopt只是一个简单的解析命令可选项的函数,只能进行简单的格式命令解析,格式如下: 1.形如:cmd [-a][-b] //对短选项的解析: ...