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- ...
随机推荐
- mysql数据库报错 sql 1452 Cannot add or update a child row:a foreign key constraint fails
其实这句话的意思就是你添加一个值是一个外键,但是这个外键不在关联的数据库中的主键中,这样就导致了添加失败了,解决办法就是添加对应关联数据库的主键的值,不过我要提醒一下!(也就是我采的坑!) 一定要看清 ...
- c++学习笔记(入门)
1 struct和class的区别 struct成员变量(成员函数)的访问属性缺省的情况下默认为public. class成员变量(成员函数)的访问属性缺省的情况下默认为private. 2 初始化列 ...
- Node.js躬行记(25)——Web自动化测试
网页在提测流转给 QA 后,如何能帮他们更有效而准确的完成测试,是我一直在思考的一个问题. QA 他们会对网页编写测试用例,在提测之前会让我们将优先级最高的用例跑通,这在一定程度上能够避免频繁的返工, ...
- 微服务系列之服务监控 Prometheus与Grafana
1.为什么需要监控服务 监控服务的所属服务器硬件(如cpu,内存,磁盘I/O等)指标.服务本身的(如gc频率.线程池大小.锁争用情况.请求.响应.自定义业务指标),对于以前的小型单体服务来说,确实 ...
- vuex的使用详解
一.下载vuex 在store文件夹下的index.js中 官方文档:https://vuex.vuejs.org/zh/ 需要使用的页面 sotre中 mutations的调用方法 store ...
- vue 单独封装分页组件
一.在components文件夹下新建 pagination.vue <template> <div class="page-wrap"> <ul&g ...
- AcWing342. 道路与航线
原题链接 解题思路 这题用\(SPFA\)会被卡,所以我们不能用\(SPFA\) 但是观察数据我们可以发现对于道路,\(0≤C_i≤10^{5}\) 所以对于每个连通块(内部不存在航线),我们可以用\ ...
- vlc qt player 播放器开发实例
(一)VLC-Qt下载 官网地址:https://vlc-qt.tano.si/ Github 地址:https://github.com/vlc-qt 示例地址:https://github.com ...
- 痞子衡嵌入式:Farewell, 我的写博故事2022
-- 题图:苏州荷塘月色 2022 年的最后一天,写个年终总结.困扰大家三年之久的新冠疫情终于在 12 月全面放开了,痞子衡暂时还没有阳,计划坚持到总决赛.对于 2023 年,痞子衡还是充满期待的,慢 ...
- [OpenCV实战]12 使用深度学习和OpenCV进行手部关键点检测
目录 1 背景 2 实现 3 结果和代码 4 参考 手部关键点检测是在手指上找到关节以及在给定图像中找到指尖的过程.它类似于在脸部(面部关键点检测)或身体(人体姿势估计)上找到关键点.但是手部检测不同 ...