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 ;
}
代码
最新文章
- bootstrap走动的进度条
- 为 Neutron 准备物理基础设施(I) - 每天5分钟玩转 OpenStack(75)
- C++中的4个类型转换关键字
- IOS开发--微信支付
- c++必读
- 转:Java面试题集(1-50)
- easyUI之message
- BZOJ1821: [JSOI2010]Group 部落划分
- Python3 学习第五弹:类与面向对象
- cocos2d_x iconv转码
- C/C++ 框架,类库,资源集合
- android开发之调试技巧 分类: android 学习笔记 2015-07-18 21:30 140人阅读 评论(0) 收藏
- VMware vSphere 服务器虚拟化之十七 桌面虚拟化之安装View链接服务器
- Android BLE与终端通信(二)——Android Bluetooth基础科普以及搜索蓝牙设备显示列表
- 如何查看github排行热度
- ReactNative常用组件汇总
- 使用padding值控制控件的隐藏与显示
- C# delegate (001)
- hdu 4612 边双联通 ***
- python之函数用法all
热门文章
- 基于RHEL8/CentOS8的网络IP配置详解
- springboot的推荐模板引擎-Thymeleaf
- 取消页面按钮的enter按下事件
- 错误:the apk for your currently selected variant(app-release-unsigned.apk)is not signed.Please specity a signing configuration for this variant(release)
- spring文件的上传和下载
- 读书笔记「Python编程:从入门到实践」_3.列表简介
- C语言-重写strupr函数
- Robot Framework(二)测试数据语法
- springboot-helloworld实现
- SQL SEVER (ROLLUP与CUBE,ROW_NUMBER())使用方法