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