Pluto_Rabbit's Blog

蒟蒻妹纸一枚,轻拍

NOIP2014 TG T6 解方程

Jacinth posted @ 2015年8月04日 08:22 in NOIP with tags NOIP Learning 数论 , 631 阅读

NOIP2015都快来了,窝还在订正2014的题,484太弱了啊

听了某大神的数论,就开始做这道当年看完题目就弃疗的题~~~

然后怎么写都不对。。。

最后猛然发现自己的错误在warning里面被提醒过一遍

果真是自己傻B了。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define MM 1000010
using namespace std;

const int mod[] = {10007,10917,30071};
char s[10010];
int n,m,l;
long long a[110][5],f[MM][5];
long long ans[MM];

bool check(int xx,int yy)
{
	long long tmp=0;
	for (int i=n;i>=0;--i)
	{
		tmp=(tmp*xx+a[i][yy])%mod[yy];
	}
	return tmp!=0;
}

int main()
{

	cin>>n>>m;
	for (int w=0;w<=n;++w)
	{
		scanf("%s",s);
		l=strlen(s);
		bool ff=0;
		for (int i=0;i<l;++i)
		{
			if (s[i]=='-') ff=1;
			else
			for (int j=0;j<3;++j)
			{
				a[w][j]=(a[w][j]*10+s[i]-'0')%mod[j];
			}
		}
		if (ff) for (int j=0;j<3;++j) a[w][j]=mod[j]-a[w][j];
	}
	ans[0]=0;
	for (int j=0;j<3;++j)
		for (int i=0;i<mod[j];++i)
		f[i][j]=check(i,j);
	for (int i=1;i<=m;++i)
	{
		bool ff=1;
		for (int j=0;j<3;++j)
		{
			if (f[i%mod[j]][j]) {
				ff=0; break;
			}
		}
		if (ff)	ans[++ans[0]]=i;
	}
	printf("%d\n",ans[0]);  
	for (int i=1;i<=ans[0];++i) printf("%d\n",ans[i]);  
	return 0;
}

get√技能~~~傲娇地无视掉warning。。。

以后努力不这么做。。。兹磁哦


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter