Codeforces Round #137 (Div. 2), problem: (C)
来源:互联网 发布:安卓怎么玩java游戏 编辑:程序博客网 时间:2024/04/30 20:38
大神代码直接看瞎了,收获好大。。。
By Shik, contest: Codeforces Round #137 (Div. 2), problem: (C) Reducing Fractions, Accepted, #
#include <cstdio>#include <cstring>#include <algorithm>#define N 100010#define S 10000010#define SZ(x) ((int)(x).size())#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )using namespace std;int p[S];void predo() {for ( int i=2; i*i<S; i++ ) if ( !p[i] ) for ( int j=i*i; j<S; j+=i ) p[j]=i;for ( int i=2; i<S; i++ ) if ( !p[i] ) p[i]=i;}void shik( int n, int s[], int t[] ) {for ( int i=0; i<n; i++ ) for ( int j=s[i]; j>1; j/=p[j] ) t[p[j]]++;}void meow( int n, int s[], int t[] ) {for ( int i=0; i<n; i++ ) {int x=1;for ( int j=s[i]; j>1; j/=p[j] ) {if ( t[p[j]]>0 ) t[p[j]]--;else x*=p[j];}printf("%d%c",x,i==n-1?'\n':' ');}}int n,m,a[N],b[N],x[S],y[S];int main(){predo();scanf("%d%d",&n,&m);for ( int i=0; i<n; i++ ) scanf("%d",a+i);for ( int i=0; i<m; i++ ) scanf("%d",b+i);printf("%d %d\n",n,m);shik(n,a,x); shik(m,b,y);meow(n,a,y); meow(m,b,x);return 0;}
- Codeforces Round #137 (Div. 2), problem: (C)
- Codeforces Round #173 (Div. 2) Problem C
- Codeforces Round #Pi (Div. 2) Problem C
- Codeforces Round #363 (Div. 2), problem: (C)
- Codeforces Round #112 (Div. 2) C Another Problem on Strings
- Codeforces Round #198 (Div. 2) C. Tourist Problem - 找规律
- Codeforces Round #198 (Div. 2) C. Tourist Problem
- Codeforces Round #198 (Div. 2) C. Tourist Problem
- Codeforces Round #209 (Div. 2), problem: (C) Prime Number
- Codeforces Round #221 (Div. 2) (Problem 376A~C)
- Codeforces Round #136 (Div. 2) C. Little Elephant and Problem
- Codeforces Round #FF (Div. 2) Problem C DZY Loves Sequences
- Codeforces Round #112 (Div. 2) C. Another Problem on Strings
- Codeforces Round #292 (Div. 2) Problem C - Drazil and Factorial
- Codeforces Round #112 (Div. 2) C Another Problem on Strings
- Codeforces Round #320 (Div. 2)C. A Problem about Polyline
- Codeforces Round #320 (Div. 2) C. A Problem about Polyline
- Codeforces Round #320 (Div. 2) C - A Problem about Polyline
- ubuntu jdk环境变量配置
- 羌笛声声胡笳怨,此心长寄天涯远
- 断想
- 浮华落寂
- 唠唠叨叨又七夕
- Codeforces Round #137 (Div. 2), problem: (C)
- 一生何求
- 简单 却爱
- 母亲的唠叨
- 16个经典面试问题回答思路
- 那时,我们正年轻
- 余杭上线顺利
- 七夕夜、离别,涵情经河岸
- 路上看水