跟 51Nod 1356 代数数的次数 是一样的
不过这里都是质数 也就是就是 2n2^n
关键是输方案 这个不一定有二次剩余

感谢sxt
一个一个数加进答案 转化成 已知F(x)F(x),求F(x+a√)F(x+\sqrt a)和F(x−a√)F(x-\sqrt a)的系数
这个推一下就是一个FFT

拷了myy的板子 自己的太慢了QAQ

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define cl(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;inline void write(int x){if (x>=10) write(x/10);putchar('0'+x%10);
}const int P=1e9+7;inline ll Pow(ll a,int b){ll ret=1;for (;b;b>>=1,a=a*a%P)if (b&1)ret=ret*a%P;return ret;
}const int N=262144;namespace MYY{
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }typedef long long LL;const int oo = 0x3f3f3f3f;const int Mod = 1e9 + 7;const int max0 = 262144;struct comp{double x, y;comp(): x(0), y(0) { }comp(const double &_x, const double &_y): x(_x), y(_y) { }};inline comp operator+(const comp &a, const comp &b) { return comp(a.x + b.x, a.y + b.y); }inline comp operator-(const comp &a, const comp &b) { return comp(a.x - b.x, a.y - b.y); }inline comp operator*(const comp &a, const comp &b) { return comp(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); }inline comp conj(const comp &a) { return comp(a.x, -a.y); }const double PI = acos(-1);int N, L;comp w[max0 + 5];int bitrev[max0 + 5];void fft(comp *a, const int &n){REP(i, 0, n) if (i < bitrev[i]) swap(a[i], a[bitrev[i]]);for (int i = 2, lyc = n >> 1; i <= n; i <<= 1, lyc >>= 1)for (int j = 0; j < n; j += i){comp *l = a + j, *r = a + j + (i >> 1), *p = w;REP(k, 0, i >> 1){comp tmp = *r * *p;*r = *l - tmp, *l = *l + tmp;++l, ++r, p += lyc;}}}inline void fft_prepare(){REP(i, 0, N) bitrev[i] = bitrev[i >> 1] >> 1 | ((i & 1) << (L - 1));REP(i, 0, N) w[i] = comp(cos(2 * PI * i / N), sin(2 * PI * i / N));}inline void conv(int *x, int *y, int *z){REP(i, 0, N) (x[i] += Mod) %= Mod, (y[i] += Mod) %= Mod;static comp a[max0 + 5], b[max0 + 5];static comp dfta[max0 + 5], dftb[max0 + 5], dftc[max0 + 5], dftd[max0 + 5];REP(i, 0, N) a[i] = comp(x[i] & 32767, x[i] >> 15);REP(i, 0, N) b[i] = comp(y[i] & 32767, y[i] >> 15);fft(a, N), fft(b, N);REP(i, 0, N){int j = (N - i) & (N - 1);static comp da, db, dc, dd;da = (a[i] + conj(a[j])) * comp(0.5, 0);db = (a[i] - conj(a[j])) * comp(0, -0.5);dc = (b[i] + conj(b[j])) * comp(0.5, 0);dd = (b[i] - conj(b[j])) * comp(0, -0.5);dfta[j] = da * dc;dftb[j] = da * dd;dftc[j] = db * dc;dftd[j] = db * dd;}REP(i, 0, N) a[i] = dfta[i] + dftb[i] * comp(0, 1);REP(i, 0, N) b[i] = dftc[i] + dftd[i] * comp(0, 1);fft(a, N), fft(b, N);REP(i, 0, N){int da = (LL)(a[i].x / N + 0.5) % Mod;int db = (LL)(a[i].y / N + 0.5) % Mod;int dc = (LL)(b[i].x / N + 0.5) % Mod;int dd = (LL)(b[i].y / N + 0.5) % Mod;z[i] = (da + ((LL)(db + dc) << 15) + ((LL)dd << 30)) % Mod;}}}int A[N],B[N],C[N],D[N],E[N],F[N];#define read(x) scanf("%d",&(x))int m,num[N];
ll fac[N],inv[N];int n;
ll f[N];int main(){int T;freopen("t.in","r",stdin);freopen("t.out","w",stdout);read(T);fac[0]=1; for (int i=1;i<N;i++) fac[i]=fac[i-1]*i%P;inv[1]=1; for (int i=2;i<N;i++) inv[i]=(ll)(P-P/i)*inv[P%i]%P;inv[0]=1; for (int i=1;i<N;i++) inv[i]=inv[i]*inv[i-1]%P;while (T--){read(m); for (int i=1;i<=m;i++) read(num[i]);cl(f); cl(C); cl(D); cl(E); cl(F);f[0]=0; f[1]=1; n=2; for (int t=1;t<=m;t++){MYY::L = 0;for ( ; (1 << MYY::L) < (n<<2); ++MYY::L);MYY::N = 1 << MYY::L;MYY::fft_prepare();for (int i=0;i<=n;i++){A[i]=f[n-i]*fac[n-i]%P;if (~i&1) B[i]=Pow(num[t],i>>1)*inv[i]%P;}MYY::conv(A,B,C);for (int i=0;i<(n<<2);i++) A[i]=B[i]=0;for (int i=0;i<=n;i++)E[i]=C[n-i]*inv[i]%P;for (int i=1;i<=n;i++){A[i]=f[n-i]*fac[n-i]%P;if (i&1) B[i]=Pow(num[t],i>>1)*inv[i]%P;}MYY::conv(A,B,D);for (int i=0;i<(n<<2);i++) A[i]=B[i]=0;for (int i=0;i<=n;i++)F[i]=D[n-i]*inv[i]%P;MYY::conv(E,E,E);MYY::conv(F,F,F);for (int i=0;i<=(n<<1);i++)f[i]=(E[i]+P-(ll)F[i]*num[t]%P)%P;n<<=1;}write(n>>1); putchar('\n');for (int i=0;i<=(n>>1);i++)write(f[i]),putchar(' ');putchar('\n');}return 0;
}

[数学 FFT] Codechef July Challenge 2017 #APRPS Irrational Root相关推荐

  1. CFCC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries

    https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...

  2. codechef October Challenge 2017解题报告

    第二次打challenge..果然还是拿不到钱(艹不过大佬)啊. A Balanced Contest 模拟就好. #include <bits/stdc++.h> #define gc ...

  3. Codechef July Challenge 2018 : Subway Ride

    传送门 首先(想了很久之后)注意到一个性质:同一条边有多种颜色的话保留3种就可以了,这是因为假如最优解要求当前位置与相邻两条边都不相同,那么只要有3条边,就肯定可以满足这一点. 完事就做一个nlogn ...

  4. CodeChef June Challenge 2017

    好气啊,本来以为比赛时间还有很多,结果回家养病两天回到学校怎么比赛就结束了(雾),大约是小高考弄错了时间? 挑3道有意思的写写题解吧. Cloning 题目大意:给一个序列,每次询问两个等长区间,问区 ...

  5. codechef November Challenge 2017解题报告

    第二次被ceilks艹翻的无奈啊.. Villages and Tribes 模拟不解释 #include <bits/stdc++.h> #define gc getchar() #de ...

  6. 【斜率优化】Codechef July Challenge 2019——Hit the Coconuts

    前言 能够自己推出斜率优化的式子了...实属难得... 不过定义和实现都是参考了别人的博客的,╮(╯▽╰)╭... woc...写博客的时候发现自己推的式子的变量有点问题.../难受 题目 All s ...

  7. July Challenge 2017 | Whats in the Name

    题意 Nitika 读了一本历史书,想要理清其中的人物关系.因此她要她的哥哥把书中出现的历史人物全部列出来.哥哥把列好的人名给了 Nitika,但 Nitika 非常不满意,因为哥哥列出的这些人名格式 ...

  8. CodeChef March Challenge 2017 题解

    CC XENTASK 由于要交替选,所以要不第一个人选位置为奇数的数,第二个人选位置为偶数的数,要不第一个人选位置为偶数的数,第二个人选位置为奇数的数.取最小值即可. #include <cst ...

  9. 亚马逊采摘挑战赛APC:6D姿态估计的多视图自我监督深度学习6D Pose Estimation in the Amazon Picking Challenge—2017(笔记)

    Multi-view Self-supervised Deep Learning for 6D Pose Estimation in the Amazon Picking Challenge-2017 ...

  10. 【视觉目标跟踪最高峰】VOT Challenge 2017 亚军北邮团队技术分享(附代码)

    视觉跟踪领域国际顶级赛事 Visual-Object-Tracking Challenge (VOT) 2017年结果出炉,结合传统滤波及深度学习的方案取得最佳成绩.本文是第二名北京邮电大学代表团队的 ...

最新文章

  1. linux jenkins远程脚本,在Jenkins中配置执行远程shell命令(转)
  2. C++ 函数--幽径初探索
  3. MATLAB基本操作(六):矩阵操作的相关函数
  4. Tensorflow实现自动编码器
  5. 【数据结构与算法】之深入解析“分割回文串II”的求解思路与算法示例
  6. *PAT_B_1052_C++(20分)
  7. 服务器端 OR 客户端
  8. 浏览器js 获取手机标识信息_手机软件多次要求获取手机信息,习惯性让其通过有安全隐患?...
  9. 大工计算机基础在线作业答案,大工1209《计算机应用基础》在线作业123.doc
  10. 13.业务层的事务操作
  11. amd cpu不能在cmd环境下运行java代码_Golang安装与环境搭建并在VSCode里面输出HelloWord...
  12. 机器学习实战笔记(Python实现)-01-K近邻算法(KNN)
  13. Ubuntu下利用QSS、WPS破解wpa/wpa2加密
  14. HTC Z710t解锁 获取root权限
  15. ngrok服务的编译与环境搭建
  16. 转帖:三种快乐物质——多巴胺、血清素、内啡肽
  17. 计算机键盘图 指法,键盘指法练习图
  18. matlab怎么做多元非线性拟合,如何用matlab进行多元非线性拟合
  19. MSSQL 负载均衡(Moebius)
  20. GOlang将华氏温度转换为摄氏温度的函数

热门文章

  1. oracle用户新建和授权,oracle创建用户及受权
  2. C语言双人贪吃蛇游戏瘦身版本
  3. 从北京回来的年轻人,我该告诉你点什么? 1
  4. cesium导入骨骼动画
  5. c语言模拟扫雷小游戏
  6. HDFS中NameNode和Secondary NameNode
  7. 计算机系统最重要的是什么,操作系统最重要的两个作用是什么
  8. Oracle归档日志路径的三个参数DB_RECOVERY_FILE_DEST和LOG_ARCHIVE_DEST和LOG_ARCHIVE_DEST_n区别
  9. 软件工程——团队答辩
  10. Python 字符串重复判断