UVA - 11728 Alternate Task (唯一分解定理)
来源:互联网 发布:空气监测软件 编辑:程序博客网 时间:2024/05/29 13:25
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 numberand the others have to tell the sum of its factors. The first one to say itcorrectly wins. After a while they got bored and wanted to try out a differentgame. Hassan then suggested about trying the reverse. That is, given a positivenumberS, they have to find a numberwhose factors add up to S. Realizingthat this task is tougher than the original task, Hasan came to you forhelp. Luckily Hasan owns a portableprogrammable device and you have decided to burn a program to this device.Given the value of S as input to theprogram, it will output a number whose sum of factors equal toS.
Input
Each case of input will consist of a positive integer S<=1000. The last case is followedby a value of 0.
Output
Foreach case of input, there will be one line of output. It will be a positiveinteger whose sum of factors is equal toS.If there is more than one such integer, output the largest. If no such numberexists, output-1. Adhere to theformat shown in sample output.
Sample Input Output for Sample Input
1
102
1000
0
Case 1: 1
Case 2: 101
Case 3: -1
ProblemSetter: Shamim Hafiz, Special Thanks: Sohel Hafiz
题意:输入一个正整数S,求一个最大的正整数N,使得N的所有因子的和是S
思路:统计1000内的数的因子和,求解
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1005;int s, sum[maxn];void init() {memset(sum, 0, sizeof(sum));for (int i = 1; i < maxn; i++)for (int j = 1; j <= i; j++)if (i % j == 0)sum[i] += j;}int main() {int cas = 1;init();while (scanf("%d", &s) != EOF && s) {int flag = 0;printf("Case %d: ", cas++);for (int i = 1000; i >= 1; i--) {if (sum[i] == s) {printf("%d\n", i);flag = 1;break;}}if (!flag)printf("-1\n");}return 0;}
- UVA - 11728 Alternate Task (唯一分解定理)
- UVa:11728 Alternate Task
- UVA 11728 - Alternate Task (数论)
- uva 11728 - Alternate Task(数论)
- uva 10375 唯一分解定理
- uva 1635 唯一分解定理
- UVA 10375 唯一分解定理
- UVa 10375 唯一分解定理
- UVa 10791 唯一分解定理
- uva 10375 唯一分解定理
- uva 10375 (唯一分解定理+筛素数)
- UVA 10375 Choose and divide(唯一分解定理)
- UVA 10791 Minimum Sum LCM(唯一分解定理)
- UVA 294 Divisors(唯一分解定理 + 除数函数)
- UVA - 10791 - Minimum Sum LCM(唯一分解定理)
- UVA 1635-Irrelevant Elements(唯一分解定理)
- UVA 10375 Choose and divide(唯一分解定理)
- UVA 10375 Choose and divide (唯一分解定理)
- Jquery鼠标滑过图片抖一下
- 政府门户建设之新技术应用
- spring framework 4 源码阅读(2)---从ClassPathXmlApplicationContext开始
- 【翻译】ASP.NET MVC中你必须知道的13个扩展点
- 55分钟学会正则表达式
- UVA - 11728 Alternate Task (唯一分解定理)
- conn / as sysdba 出现ORA-01031: insufficient privileges 解决办法
- VMware打开VMDK格式文件
- 2014.08.25 获取当前页的URL 实现左侧列表被选中的状态
- SPOJ 16636. Journey
- HTTP协议(二)响应状态码
- APUE学习笔记——5缓冲Buffering、流、文件对象
- restrict
- SVN服务器搭建和使用(一)