UVA 11490-just Another problem (number theory)

Source: Internet
Author: User

11490-just Another problem

option=com_onlinejudge&itemid=8&page=show_problem&category=474&problem=2485&mosmsg= submission+received+with+id+13809788 "target=" _blank "style=" "> Topic Links

Test instructions: There's a soldier in S. In a matrix, the matrix can have two holes, requiring two holes up and down the thickness of the same, ask the number of soldiers can be missing.

Idea: Push formula, set thickness to a, square to I, then (3 A + 2 i) (2 A + i) = S + 2 i ;
A little bit to get 6 i i + 7 a i = S
Because S is very large, so go to enumerate the thickness. This is enough to enumerate only to sqrt (S), and the complexity can be acceptable.

Code:

#include <stdio.h> #include <string.h> #include <math.h>const long long MOD =100000007;long long n;int Main () {while (~scanf ("%lld", &n) && n) {int flag = 1;for (Long long i = 1; I * I * 6 < n; i++) {Long long TMP = n-i * I * 6;IF (tmp% (7 * i) = = 0) {Long long ans = tmp/(7 * i)% mod;printf ("Possible Missing soldiers =%lld\ N ", ans * ans * 2 MOD); flag = 0;   }  }  if (flag) printf ("No solution possible\n");  printf ("\ n"); }return 0;}


UVA 11490-just Another problem (number theory)

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.