"Number theory, water problem" UVa 11728-alternate Task

Source: Internet
Author: User

Topic links

Test instructions: Give a number S, ask for a maximum number, so that the sum of all the factors of this number is s;

The so-called "factor sum" does not know that there is no misleading, because at first thought is a prime number. Later reviewed the next primary mathematics, such as 12 of the factors are 1,2,3,4,6,12 ...

I was speechless t^t ...

The sense of complexity should continue to be optimized. I didn't think so.

Code:

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <cmath>6 using namespacestd;7 Const intMAXN =1010;8 intVIS[MAXN], PRIME[MAXN], CNT;9 voidPre ()Ten { One     intm = sqrt (maxn+0.5); Avis[0] =1; -vis[1] =1; -      for(inti =2; I <= m; i++) the         if(!Vis[i]) -              for(intj = i*i; J < Maxn; j+=i) -VIS[J] =1; -CNT =0; +      for(inti =2; i < MAXN; i++) -         if(!Vis[i]) +prime[cnt++] =i; A } at  - intMain () - { - pre (); -     intS, Kase =0; -      while(~SCANF ("%d", &s) &&S) in     { -         if(S = =1) {printf ("Case %d:1\n", ++kase);Continue;} to         BOOLexist =false; +         inti; -          for(i = s1; I >=1; i--) the         { * //if (!vis[i]) $ //            {Panax Notoginseng                 //cout << i << Endl; -                 intsum =0;BOOLOK =true; the                  for(intj =1; J <= sqrt (i); J + +) +                 { A                     intTMP = i/J; the                     //cout << tmp << Endl; +                     if(Sum > S) {OK =false; Break;} -                     if(Tmp*j! = i)Continue; $                     if(tmp! = j) Sum + =J; $Sum + =tmp; -                 } -                 if(sum = = S) {exist =true; Break;} the //            } -         }Wuyi         if(exist) printf ("Case %d:%d\n", ++Kase, i); the         Elseprintf"Case %d: -1\n", ++Kase); -  Wu     } -     return 0; About}
View Code

"Number theory, water problem" UVa 11728-alternate Task

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.