您的位置:首页 > 其它

[杂题]CSUOJ1413 Area of a Fractal

2014-12-08 22:41 204 查看
题目链接

题意:题中给了图,所以不看字大概也知道

   求的是第n个图形的面积。

就是找规律 递推 一类的...

先给结论:

很鬼畜的公式: $\displaystyle\frac{3\times 17^n+2\times 7^n}{5}$

递推式是: $\displaystyle S_n = S_{n-1}\times 17-4\times 7^{n-1}$

重点在于17和7是怎么来的。

在题图的基础上画些个框框

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <cmath>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
typedef long long LL;
typedef long double LD;
const double pi=acos(-1.0);
const double eps=1e-6;
#define INF 0x3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
typedef pair<int, int> PI;
typedef pair<int, PI > PP;
#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//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;}
inline void print(LL x){printf(LLD, x);puts("");}
//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 int mod=1000000007;

LL quick(LL a, LL b)
{
LL ans=1;
while(b)
{
if(b & 1)ans=(ans*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return ans%mod;
}

void ex_gcd(int a, int b, int &x, int &y)
{
if(b)
{
ex_gcd(b, a%b, x, y);
int tmp=x;
x=y;
y=tmp-(a/b)*y;
}
else
{
x=1, y=0;
return ;
}
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n;
scanf("%d", &n);
if(n==0)
{
printf("1\n");
continue;
}
int x, y;
ex_gcd(5, mod, x, y);
print((((3*quick(17, n))%mod+(2*quick(7, n))%mod)*x)%mod);
}
return 0;
}


CSUOJ 1413
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: