Poj-1142 Smith number (factorization factors)

Source: Internet
Author: User

Question:

A number is decomposed into quality factors and multiplied. The sum of each bit of the original number is equal to the sum of all the decomposed numbers.

This is the decomposition factor + enumeration. Note that prime numbers cannot be calculated.

# Include <stdio. h> typedef long ll; void bitsum (ll n, ll * s) {int t; while (n) {T = n % 10; N/= 10; * s + = T ;}} int main () {ll num, ANS, TMP; ll sum1, sum2; bool flag; // flag is used to mark whether a number is a prime number. While (scanf ("% LLD", & num), num) {If (num = 1) num = 2; while (Num ++) {sum2 = sum1 = 0; TMP = num; ans = num; flag = 0; bitsum (TMP, & sum1); While (TMP & 1) = 0) {TMP >>= 1; sum2 + = 2; flag = 1;} For (ll I = 3; I * I <= TMP; I + = 2) {While (TMP % I = 0) {tmp/= I; bitsum (I, & sum2); flag = 1 ;}} if (TMP> 1) bitsum (TMP, & sum2); If (sum1 = sum2 & flag) {printf ("% LLD \ n", ANS); break ;}}}}

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.