UVA 11728-alternate Task Math

Source: Internet
Author: User
Tags cas

Little Hasan loves to play number games with his friends. One day they were playing a game where
One of them would speak out a positive number and the others has the sum of its factors. The
? rst one to say it correctly wins. After a while they got bored and wanted to try out a di?erent game.
Hassan then suggested about trying the reverse. That is, given a positive number S, they has to? nd
A number whose factors add up to S. Realizing that this task is tougher than the original task, Hasan
Came to the help. Luckily Hasan owns a portable programmable device and you had decided to
Burn a program to this device. Given the value of S as input to the program, it would output a number
whose sum of factors equal to S.
Input
Each case of input would consist of a positive integer s≤1000. The last case was followed by a value of
' 0 '.
Output
For each case of input, there'll be is one line of output. It'll 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

Test Instructions : give you a S, ask you n the number of factors and for S, ask N

The puzzle: s is very small, to find the n factor and S, the array inversion is good

#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespacestd; typedefLong Longll;Const intn= +;intB[m +5], B[n +5];voidinit () {memset (A,-1,sizeof(a));  for(inti =1; I <= N; i++) {     for(intj = i; J <= N; J + =i) {b[j]+=i; }    if(B[i] < N) A[b[i]] =i;}}intMain () {init (); intCAS =1, N;  while(~SCANF ("%d",&N)) {if(n = =0) Break; printf ("Case %d:%d\n", cas++, A[n]); }    return 0;}
Code

UVA 11728-alternate Task Math

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.