Ultraviolet-11490 just another problem (Factorization)

Source: Internet
Author: User

 

There is a wise saying "nothingis unfair in love and war ". probably that is why emperors of specified ent days usedto use your funny and clever tricks to fool the opponents. the most commontechnique was to scare the opponent away by out numbering them with imaginarysoldiers. one of the funnier tricks (though hard to believe) was to give theown soldiers (not the opponent soldiers !) Mild laxative dose so that there is along queue of soldiers in front of toilet. seeing this queue from a distancethe opponent wocould miscalculate the total number of soldiers and flee away. this was a famous trick given by famous clown of the sub-continent named Gopal (the infamous "Gopal Bhar" to be precise ). another most common trick was tohave square shaped holes while arranging the soldiers in rows and columns. suchan arrangement is shown below with 96 soldiers.

 


Fig: a valid layout with 96 soldiers. After arranging them 8 soldiers are missing.

 

The strict property of sucharrangement for this problem is as follows:

 

(A) The soldiershave to be arranged in rows and columns.

(B) the Border of thearrangement has to be rectangular.

(C) The arrangementshoshould have soldiers missing only from the inner layers.

(D) The soldiers shoshould bemissing only from two equal square shaped regions. so the number of missingsoldiers shoshould be twice of a strictly positive square number. in the figureabove the number of missing soldier is 2*22.

(E) The thickness ofsoldiers shoshould be equal every where (should t the corners) in horizontal andvertical directions along the missing square. for example in the figure abovethe thickness of soldiers in horizontal and vertical directions along themissing square is always three.

 

Now given the total number ofsoldiers s your job is to determine whether or not they can be arrangedaccording to the above mentioned rules.

 

Input

The input file contains 1000 lines of inputs. Each line contains a positive integer S (S <1000000000000), where S is the total number of soldiers.

 

Input is terminated by linecontaining a single zero.

 

Output

For each line of input produceone or more line of output. each line reports one possible number of possiblemissing soldiers which wocould enable the desired arrange with the S soldiers. asthe number of possible missing soldiers can be quite large so instead of theactual number, the modulo 100000007 value shocould be printed. also if there ismore than one possible value for number of missing soldiers the modulo00000007 values shocould be reported in descending order of the original numberof soldier (not the modulo value ). if no such number of missing soldiers isfound print the line "no solution possible" instead.

 

Print a blank line after Theoutput for each line of input. Look at the output for sample input for details.

 

Sample input output for sample input

96

102

11100

0

Possible missing soldiers = 8

 

No solution possible

 

Possible missing soldiers = 553352

Possible missing soldiers = 308898

Possible missing soldiers = 45000

Possible missing soldiers = 3528

 

Problem setter: shahriarmanzoor

Special thanks: Syed monowarhossain.

You have s soldiers and want to arrange them into a matrix of column C in the r row, but you can have two "holes" in the rectangle, the boundary of the team must be composed of people standing, and the "thickness" of each four directions of each hole is the same.

Idea: If the thickness is set to a, we can get: (3A + 2C) * (2a + C) = S + 2 * C ^ 2, introducing 6a ^ 2 + 7ac = s, then enumerate.

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>typedef long long ll;using namespace std;const ll mod = 100000007;ll n;int main() {while (scanf("%lld", &n) != EOF && n) {ll m = sqrt(n/6+0.5);int flag = 0;for (ll i = 1; i <= m; i++) {if ((n-6*i*i) % (7*i) == 0) {ll cur = (n-6*i*i) / (7*i);if (cur <= 0)continue;cur %= mod;flag = 1;printf("Possible Missing Soldiers = %lld\n", (2*(cur*cur%mod))%mod);}}if (!flag)printf("No Solution Possible\n");printf("\n");}return 0;}


Ultraviolet-11490 just another problem (Factorization)

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.