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 数学的更多相关文章

  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

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

  5. UVa 11728 Alternate Task (枚举)

    题意:给定一个 n,求一个最大正整数 N 使得 N 的所有正因数和等于 n. 析:对于任何数一个 n,它的所有正因子都是大于等于本身的,因为 n 本身就是自己的正因数,这样的就可以直接暴力了,答案肯定 ...

  6. 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任选 ...

  7. woj1010 alternate sum 数学 woj1011 Finding Teamates 数学

    title: woj1010 alternate sum 数学 date: 2020-03-10 categories: acm tags: [acm,woj,数学] 一道数学题.简单. 题意 给一个 ...

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

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

  9. UVa 1639 - Candy(数学期望 + 精度处理)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. Java基础学习分享

    一.Java介绍 Java是由原Sun公司(现已被甲骨文公司收购)于1991年开发的编程语言,初衷是为智能家电的程序设计提供一个分布式代码系统.为了使整个系统与平台无关,采用了虚拟机器码方式,虚拟机内 ...

  2. python求两个列表的并集.交集.差集

    求两个列表的差集 >>> a = [1,2,3] >>> b=[1,2] >>> ################################ ...

  3. shell 杂集

    1.shell 相等比较注意 -eq 数字相等的比较 == 字符串相等的比较 2.== 和 = 的区别 == 可用于判断变量是否相等,= 除了可用于判断变量是否相等外,还可以表示赋值. = 与 ==  ...

  4. 创建一个netcore2.0和angular的项目并运行起来

    netcore2.0发布了,喜大普奔. 我们先下载SDK,请看张善友老师的这篇博客 http://www.cnblogs.com/shanyou/p/7363037.html 下载完之后 我用的vs2 ...

  5. 洛谷P2607 [ZJOI2008]骑士(树形dp)

    题目描述 Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的Y国发动了一场针对Z国的侵略战争.战火绵延五百里, ...

  6. [C]关于交换

    交换(c,c++): 1)temp交换(也适用于非数型) 定义一个新的变量,借助它完成交换. int a,b; a=10; b=15; int t; t=a; a=b; b=t; 2)位运算 位运算不 ...

  7. Daily Build[called heart beat]

    ###Daily Build->Object File&Binary File->Deploymened on release server->BVT Automation. ...

  8. vue-阻止事件冒泡-开启右键-键盘类事件

    一: 阻止事件冒泡 布局: 当点击按钮时,会触发button的click 也会触发父级的方法 <div id="box"> <div @click="p ...

  9. ASP.NET 微信公众平台模板消息推送功能完整开发

    最近公众平台的用户提出了新需求,他们希望当收到新的邮件或者日程的时候,公众平台能主动推送一条提醒给用户.看了看平台提供的接口,似乎只有[模板消息]能尽量满足这一需求,但不得不说微信提供的实例太少,而且 ...

  10. preparedStatement平台:

    public class cs{ public static void main(String[] args){ try{ class.forName("com.mysql.jdbc.Dri ...