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)