hdu 4447 Yuanfang, What Do You Think?
思路:
这题有个结论也可以自己归纳:
对于给定的n,其约数用pi表示
T(n)=T(p1)T(p2)……T(pn)T(n')
其中T(n')是这个式子所独有的也就是
T(n')=(x^n-1)/T(p1)/T(p2)……/T(pn)
代码如下:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#define MAX 1102
using namespace std;
struct pol
{
int bit[MAX],len;
void init(){memset(bit,,sizeof(bit));len=;}
}p[MAX];
int ans[MAX];
int com(pol a,pol b)
{
if(a.len!=b.len)return a.len-b.len;
for(int i=a.len-;i>=;i--)
if(a.bit[i]!=b.bit[i]){
if(abs(a.bit[i])!=abs(b.bit[i]))
return abs(a.bit[i])-abs(b.bit[i]);
return a.bit[i]-b.bit[i];
}
return ;
}
bool cmp(int a,int b)
{
return com(p[a],p[b])<;
}
void shows(int n)
{
if(n>) printf("x^%d",n);
else if(n==) printf("x");
}
void show(pol a)
{
int x;
printf("(");
for(int i=a.len-;i>=;i--){
if(a.bit[i]==) continue;
if(i==){
if(a.bit[i]>) printf("+%d",a.bit[i]);
else printf("%d",a.bit[i]);
continue;
}
if(i==a.len-){
if(a.bit[i]<) printf("-");
x=abs(a.bit[i]);
if(x>) printf("%d",x);
shows(i);
continue;
}
if(a.bit[i]<) printf("-");
else printf("+");
x=abs(a.bit[i]);
if(x>) printf("%d",x);
shows(i);
}
printf(")");
}
pol Div(pol a,pol b)
{
pol c;
c.init();
for(int i=a.len-;i>=;i--)
if(a.bit[i]){
c.bit[i-b.len+]=a.bit[i];
int cnt=,cur=a.bit[i];
for(int j=b.len-;j>=;j--){
a.bit[i-cnt]-=cur*b.bit[j];
cnt++;
}
}
c.len=a.len;
while(c.len>&&c.bit[c.len-]==) c.len--;
return c;
}
int main(){
p[].bit[]=-;
p[].bit[]=;
p[].len=;
for(int i=;i<MAX;i++){
p[i].init();
p[i].bit[i]=;p[i].bit[]=-;
p[i].len=i+;
p[i]=Div(p[i],p[]);
for(int j=;j*j<=i;j++){
if(i%j==){
p[i]=Div(p[i],p[j]);
if(j*j!=i) p[i]=Div(p[i],p[i/j]);
}
}
}
int n,m;
while(scanf("%d",&n)&&n){
if(n==){
puts("x-1");
continue;
}
m=;
for(int i=;i*i<=n;i++){
if(n%i==){
ans[m++]=i;
if(i*i!=n) ans[m++]=n/i;
}
}
sort(ans,ans+m,cmp);
for(int i=;i<m;i++)
show(p[ans[i]]);
printf("\n");
}
return ;
}
hdu 4447 Yuanfang, What Do You Think?的更多相关文章
- HDU P4578 Transformation
Problem Description Yuanfang is puzzled with the question below: There are n integers, a1, a2, …, an ...
- hdu 4578 线段树(标记处理)
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others) ...
- HDU 4578 - Transformation - [加强版线段树]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 Problem Description Yuanfang is puzzled with the ...
- HDU 4578 线段树玄学算法?
Transformation 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4578 Problem Description Yuanfang is p ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- AngularJS中的MVC模式
MVC根据逻辑关系,把前端项目的代码分为三个层次 model:模型,就是业务数据,前端项目中就是JS变量. view:视图,就是业务数据在用户面前的展现,前端项目中就是HTML. controller ...
- 万能的SQLHelper帮助类
/// <summary> /// 数据库帮助类 /// </summary> public class SQLHelper { private static string c ...
- 【转】HttpServletRequest.getParameter() &HttpServletRequest.getAttribute() 区别
Ref: HttpServletRequest的getParameter和getAttribute方法有什么区别 具体如下几点: (1)HttpServletRequest类有setAttribute ...
- 批处理bat命令--获取当前盘符和当前目录和上级目录
批处理bat命令--获取当前盘符和当前目录和上级目录 批处理命令获取当前盘符和当前目录%~d0 是当前盘符%cd% 是当前目录可以用echo %cd%进行打印测试 以下例子是命令行编译Visual S ...
- Silverlight浮动窗体 floatablewindow 非模态对话框
1.http://www.cnblogs.com/yinxiangpei/articles/2613913.html 说明:Silverlight的ChildWindow组件给我们的开发带来了便利,比 ...
- linux服务器修改ssh默认22端口方法
1.登录服务器,打开sshd_config文件 # vim /etc/ssh/sshd_config 2.找到#Port 22,默认是注释掉的,先把前面的#号去掉,再插入一行设置成你想要的端口号,注意 ...
- EcilpsePHP studio 3.0 运行(run)环境配置
EcilpsePHP studio 3.0的界面与 MyEclipse操作界面基本一样,熟悉后者的对于EcilpsePHP studio 的使用学习就不会太难了. 安装好EPP后,新建项目--> ...
- PHPcms 摘要
一 常量 /** * 主要定义了路径常量,项目中经常用到 **/ define('PHPCMS_PATH',dirname(__FILE__).DIRECTORY_SEPARATOR);// 项目 ...
- sql拆分查询
有这样一个需求: 临时表sql: create table #AA ( ID int, Name nvarchar(20) ) insert #AA select 1,'苏州/上海/温州' union ...
- #ifdef预编译相关用法
#ifdef预编译相关用法主要有:(1)#ifdef XXX executing the corresponding xxx code #endif(2)#ifdef XXX executing th ...