http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1413
Test instructions: The picture is given in the question, so I probably know it without reading the word.
The area of the nth graph is asked.
is to find a regular recursive class ...
Give the conclusion first:
The formula for a very spooky animal:
The recursive type is:
The point is how 17 and 7 are coming.
Draw thousand box on the basis of the graph
It is observed that the squares of 1*1 in Figure 1 become the squares in Figure 2.
17 of them are 4*4+1*1.
So the second square is 17 times times the size of the previous square.
Obviously it is not the area of the graph after 17 times times, because there is less area (gray lattice).
Count it and you'll find that each of the 4 turns is missing 7 bucks.
So the magical 7 and 17 have got ...
Then the solution and the solution can solve the ghost animal formula.
With the formula, it's a simple question.
Only need to use EX_GCD to find the inverse of 5, and then set a set of formulas, mold a mold is completed ~
Code:
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <climits>5#include <cctype>6#include <cmath>7#include <string>8#include <sstream>9#include <iostream>Ten#include <algorithm> One#include <iomanip> A using namespacestd; -#include <queue> -#include <stack> the#include <vector> -#include <deque> -#include <Set> -#include <map> +typedefLong LongLL; -typedefLong DoubleLD; + Const DoublePi=acos (-1.0); A Const Doubleeps=1e-6; at #defineINF 0x3f3f3f - #defineLson L, M, rt<<1 - #defineRson m+1, R, rt<<1|1 -typedef pair<int,int>PI; -typedef pair<int, PI >PP; - #ifdef _WIN32 in #defineLLD "%i64d" - #else to #defineLLD "%lld" + #endif - //#pragma COMMENT (linker, "/stack:1024000000,1024000000") the //ll Quick (ll A, ll b) {ll ans=1;while (b) {if (b & 1) ans*=a;a=a*a;b>>=1;} return ans;} * //inline int Read () {char ch= "; int ans=0;while (ch< ' 0 ' | | ch> ' 9 ') Ch=getchar (); while (ch<= ' 9 ' && Ch >= ' 0 ') {ans=ans*10+ch-' 0 '; Ch=getchar ();} return ans;} $InlinevoidPrint (LL x) {printf (LLD, x);p UTS ("");}Panax Notoginseng //inline void Read (LL &ret) {char c;int sgn; LL bit=0.1;if (C=getchar (), c==eof) return, while (c!= '-' &&c!= '. && (c< ' 0 ' | | C> ' 9 ')) C=getchar (), sgn= (c== '-'), -1:1;ret= (c== '-')? 0: (c ' 0 '); while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret=ret*10+ (c ' 0 '); if (c== "| | c== ' \ n ') {ret*=sgn; return;} while (C=getchar (), c>= ' 0 ' &&c<= ' 9 ') ret+= (c ' 0 ') *bit,bit/=10;ret*=sgn;} - Const intMod=1000000007; the + ll Quick (ll A, ll b) A { theLL ans=1; + while(b) - { $ if(B &1) ans= (ans*a)%MoD; $A= (a*a)%MoD; -b>>=1; - } the returnans%MoD; - }Wuyi the voidEX_GCD (intAintBint&x,int&y) - { Wu if(b) - { AboutEX_GCD (b, a%b, x, y); $ inttmp=x; -x=y; -Y=tmp-(A/b) *y; - } A Else + { thex=1, y=0; - return ; $ } the } the intMain () the { the intT; -scanf"%d", &t); in while(t--) the { the intN; Aboutscanf"%d", &n); the if(n==0) the { theprintf"1\n"); + Continue; - } the intx, y;BayiEX_GCD (5, mod, x, y); thePrint (((3*quick ( -, n))%mod+ (2*quick (7, n))%mod) *x)%MoD); the } - return 0; -}
Csuoj 1413
[Miscellaneous Questions] CSUOJ1413 area of a Fractal