Codeforces Round #324 (Div. 2) B. Kolya and Tanya 思维题 数论

来源:互联网 发布:i5处理器编程够用么 编辑:程序博客网 时间:2024/05/21 14:55
http://codeforces.com/contest/584/problem/B

题意:给你3n个点,均匀分散在一个圆的周围,每三个下标符合i,i+n,i+2n的点构成一个组合,
每个点可取a=1,2,3,三个数字,问给定了n后,求出有多少种圆中不存在任何一种ai+a(i+n)+a(i+2n)=6的
组合数;
错因分析:核心思想分析的出来,就是不会处理计算;
分析:若 a>b,则(a-b)%m==(a%m-b%m+m)注意中间要加个m,因为可能a%m<b%m;
AC代码:
#include <iostream>
#include<cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include<map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
int main()
{
int n;
while (~scanf("%d", &n))
{
ll s
= 27, w = 7;
for (int i = 1; i <= n - 1; i++)
{
s
= (s * 27) % (1000000000 + 7);
w
= (w * 7) % (1000000000 + 7);
}
printf
("%lld\n", ( s-w+1000000000+7)%(1000000000+7));
}
return 0;
}
WA代码:
#include <iostream>
#include<cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include<map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
int main()
{
int n;
while (~scanf("%d", &n))
{
ll s
= 27, w = 7;
for (int i = 1; i <= n - 1; i++)
{
s
= (s * 27) % (1000000000 + 7);
w
= (w * 7) % (1000000000 + 7);
}
printf
("%lld\n", s-w);
}
return 0;
}

阅读全文
0 0
原创粉丝点击