LG P1919
\(\text{FFT}\)
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#define re register
using namespace std;
const int N = 2e6 + 1e5;
int c[N], rev[N];
char s[N];
const double Pi = acos(-1.0);
struct complex{
double x, y;
inline complex(double xx = 0, double yy = 0){x = xx, y = yy;}
inline complex operator + (const complex &b) const {return complex(x + b.x, y + b.y);}
inline complex operator - (const complex &b) const {return complex(x - b.x, y - b.y);}
inline complex operator * (const complex &b) const {return complex(x * b.x - y * b.y, x * b.y + y * b.x);}
}a[N], b[N];
inline void FFT(complex *a, int lim, int inv)
{
for(re int i = 0; i < lim; i++)
if (i < rev[i]) swap(a[i], a[rev[i]]);
for(re int mid = 1; mid < lim; mid <<= 1)
{
complex I = complex(cos(Pi / mid), inv * sin(Pi / mid));
for(re int i = 0; i < lim; i += mid << 1)
{
complex W = complex(1, 0);
for(re int j = 0; j < mid; j++, W = W * I)
{
complex x = a[i + j], y = W * a[i + j + mid];
a[i + j] = x + y, a[i + j + mid] = x - y;
}
}
}
}
int main()
{
scanf("%s", s);
int n = strlen(s);
for(re int i = 0; i < n; i++) a[i].x = s[n - i - 1] ^ 48;
scanf("%s", s);
int m = strlen(s);
for(re int i = 0; i < m; i++) b[i].x = s[m - i - 1] ^ 48;
int limit = 1;
while (limit < n + m - 1) limit <<= 1;
int bit = 0;
while ((1 << bit) < limit) ++bit;
for(re int i = 0; i < limit; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
FFT(a, limit, 1), FFT(b, limit, 1);
for(re int i = 0; i < limit; i++) a[i] = a[i] * b[i];
FFT(a, limit, -1);
for(re int i = 0; i < limit; i++) c[i] = int(a[i].x / limit + 0.5);
for(re int i = 0; i < limit; i++)
{
if (c[i] >= 10) c[i + 1] += c[i] / 10, limit = ((i + 1) == limit ? limit + 1 : limit);
c[i] %= 10;
}
while (limit && !c[limit]) --limit;
for(re int i = limit; i >= 0; i--) printf("%d", c[i]);
}
\(\text{NTT}\)
#include <cstdio>
#include <iostream>
#include <cstring>
#define re register
using namespace std;
const int N = 2e6 + 1e5;
const int P = 998244353, g = 3;
int a[N], b[N], rev[N];
char s[N];
inline int fpow(int x, int y)
{
int res = 1;
for(; y; y >>= 1)
{
if (y & 1) res = 1LL * res * x % P;
x = 1LL * x * x % P;
}
return res;
}
inline void NTT(int *a, int lim, int inv)
{
if (lim == 1) return;
for(re int i = 0; i < lim; i++)
if (i < rev[i]) swap(a[i], a[rev[i]]);
for(re int mid = 1, I; mid < lim; mid <<= 1)
{
I = fpow(g, (P - 1) / (mid << 1));
if (inv == -1) I = fpow(I, P - 2);
for(re int i = 0, W; i < lim; i += mid << 1)
{
W = 1;
for(re int j = 0, x, y; j < mid; j++, W = 1LL * W * I % P)
{
x = a[i + j], y = 1LL * W * a[i + j + mid] % P;
a[i + j] = (x + y) % P, a[i + j + mid] = (x - y + P) % P;
}
}
}
}
int main()
{
scanf("%s", s);
int n = strlen(s);
for(re int i = 0; i < n; i++) a[i] = s[n - i - 1] ^ 48;
scanf("%s", s);
int m = strlen(s);
for(re int i = 0; i < m; i++) b[i] = s[m - i - 1] ^ 48;
int limit = 1;
while (limit < n + m - 1) limit <<= 1;
int bit = 0;
while ((1 << bit) < limit) ++bit;
for(re int i = 0; i < limit; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
NTT(a, limit, 1), NTT(b, limit, 1);
for(re int i = 0; i < limit; i++) a[i] = 1LL * a[i] * b[i] % P;
NTT(a, limit, -1);
int inv = fpow(limit, P - 2);
for(re int i = 0; i < limit; i++) a[i] = 1LL * a[i] * inv % P;
for(re int i = 0; i < limit; i++)
{
if (a[i] >= 10) a[i + 1] += a[i] / 10, limit = ((i + 1) == limit ? limit + 1 : limit);
a[i] %= 10;
}
while (limit && !a[limit]) --limit;
for(re int i = limit; i >= 0; i--) printf("%d", a[i]);
}
LG P1919的更多相关文章
- Linux下安装性能测试负载机LG
系统:CentOS release 6.6 (Final) x86_64 安装包: 1.LRLG_00031.iso [Load Generator Standalone (Linux 64-bit ...
- bootstrap 之 xs,sm,md,lg && 主要颜色
mobile – xs ( <768px ) tablet – sm ( 768~991px ) desktop – md ( 992~1170px ) large desktop – lg ( ...
- boostrap中lg,md,sm,xs
boostrap中lg,md,sm,xs分别表示多少px? .col-xs- 超小屏幕 手机 (<768px).col-sm- 小屏幕 平板 (≥768px).col-md- 中等屏幕 桌面显示 ...
- LG 2.2.1 P350安卓系统刷机,问题总结,希望对需要的朋友有助
手机误删软件导致短信,键盘等无声音提醒 我的手机前几天被我误删了一个软件,导致电话接不了,别人打电话的时候,老提示我在通话中,但是我可以在通话中看到对方的打电话记录.短信,键盘,USB连接,等等都没有 ...
- 美版nexus 5 LG D820才支持CDMA,国际版LG D821不支持
我们都知道nexus 5其实是有两个不同的版本的,分别是LG D820和LG D821,它们在几乎所有的配置和外观上都没有任何的区别,主要区别在通讯模块上,一个支持GSM/CDMA/WCDMA/LTE ...
- 洛谷P1919 【模板】A*B Problem升级版 题解(FFT的第一次实战)
洛谷P1919 [模板]A*B Problem升级版(FFT快速傅里叶) 刚学了FFT,我们来刷一道模板题. 题目描述 给定两个长度为 n 的两个十进制数,求它们的乘积. n<=100000 如 ...
- git lg 使用 转
命令: git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yello ...
- git lg 配置
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d ...
- 国行 lg g3 D858 刷 lg g3 D858hk 教程(备忘)
纯手打,转载请注明出处~ 刷机有风险,出现问题概不负责! 本着自娱自乐的宗旨 ,分享一下,出了问题不负责! 准备的材料: 1,手机一枚(废话)国行lg g3 d858 2,root 工具 用来root ...
- LG Optimus L90 [D415] T-Mobile 刷机
1 先使用[ROOT大师]ROOT手机. 2 执行以下ADB命令. adb shell su //备份 dd /by-name/laf of=/sdcard/laf.img. //清除 dd /by- ...
随机推荐
- 深入浅出学习透析Nginx服务器的基本原理和配置指南「Keepalive性能分析实战篇」
Linux系统:Centos 7 x64 Nginx版本:1.11.5 Nginx 是一款面向性能设计的 HTTP 服务器,能反向代理 HTTP,HTTPS 和邮件相关(SMTP,POP3,IMAP) ...
- 数电第7周周结_by_yc
一.通用双向移位寄存器: 功能描述: 4位的双向移位寄存器,含控制输入端(ctrl).串行输入端(Dsl.Dsr).4个并行输入端和4个并行输出端,要求实现5种功能:异步置零.同步置数.左移.右移 ...
- 如何使用 IdGen 生成 UID
在分布式系统中,雪花 ID 是一种常用的唯一 ID 生成算法.它通过结合时间戳.机器码和自增序列来生成 64 位整数 ID,可以保证 ID 的唯一性和顺序性. 在.Net 项目中,我们可以使用 IdG ...
- MongoDB 索引类型介绍
转载请注明出处: 目录 1.单字段索引 2.复合索引 3.多key索引 4.其他类型索引 5.索引额外属性 6.MongoDB 索引相关的常用sql命令 MongoDB 支持多种类型的索引,包括单字段 ...
- JavaScript:函数:函数的参数
声明函数的时候,有个括号,这里面可以加上函数的参数,这些参数,我们叫做形参(形式参数): 此时这些参数,也是已经声明了的变量,只是还没有赋值而已. 也可以不加,取决于函数的逻辑.如果函数需要从外部传进 ...
- [深度学习] tf.keras入门2-分类
目录 Fashion MNIST数据库 分类模型的建立 模型预测 总体代码 主要介绍基于tf.keras的Fashion MNIST数据库分类, 官方文档地址为:https://tensorflow. ...
- CentOS 7安装mysql5.7-单节点&主从
一 下载 Mysql5.7下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads Mysql精细版本存档版本下载地址:https:/ ...
- Pytorch基础-tensor数据结构
torch.Tensor Tensor 数据类型 Tensor 的属性 view 和 reshape 的区别 Tensor 与 ndarray 创建 Tensor 传入维度的方法 参考资料 torch ...
- 解决xcode每次编译都需要输入用户名和密码
MacOS:11.1 Xcode:12.3 一.打开你的 钥匙串, 如果不知道 打开你的 spotlight搜索 工具 ,输入"钥匙串" 二.登录--->iPhone de ...
- 在GCP上创建Cloud SQL的三种方式(Console,gcloud,Terraform)
1 简介 Cloud SQL 是GCP上的关系型数据库,常用的有三种方式来创建: (1) 界面操作 (2) 命令行 gcloud (3) Terraform 在开始之前,可以查看:<初始化一个G ...