传送门

题意:

  给出了三个新定义:

  1. E-prime : ∀ num ∈ E,不存在两个偶数a,b,使得 num=a*b;(简言之,num的一对因子不能全为偶数)
  2. E-prime factorization : 定义集合P由 E-prime 元素组成,定义 e = p1*p2*.....*pn;(p1,p2,....,pn ∈ P , |P| = n)
  3. E-factorial : 定义 e!! = 2*4*6*8*.........*e;(简言之,偶数e及其之前的偶数连乘积)

  输出一个数 e ,求满足条件2的集合P,并且集合P需满足:p1*p2*.....*p= e!! , |P| = n;

  求 n 的最大值;

 题解:

  定义集合 Pi 为偶数 i 的满足条件(2)的最大的集合;

  例如P8 = {2,2,2},| P8 | = 3;

  根据贪心的思想,要想使集合 Pe!! 中的元素个数最多,那么,e!! 一定要优先分解出最多的2(最小的e-prime);

  定义 odd 表示奇数,那么 odd*2 为 e-prime,因为 odd 因式分解肯定没有偶数因子,odd*2 只能分解出一个偶数因子2,符合条件(1);

  因此,对于所有的奇数 odd,可以通过让 odd*2 将 odd 转化为 e-prime,那么,我们的关注点就变成了 e!! 最多能分解出多少个2;

  对于 e 之前的所有偶数,假设 ≤ e 的最大的2的幂为 2x+1,那么对于 e 之前的所有2的幂 21,22,23,....,2x+1 其可分解出 1+2+3+......+x+1 个2;

  那 e 之前的所有非2的幂的偶数 even ,该如何快速求出他们的乘积最多能分解出多少个2呢?

  首先,求解一下 2x+1 及其之前的偶数乘积最多可以分解出多少个2;

  首先考虑这一点,任何一个偶数 even 都可分解成 odd*2i 模式, 那么 |Peven | = i;

  那么,我们反过来考虑,对于任意奇数 odd 都可通过 odd*2i 求出 | Podd*2i | = i;

  

      (每两个相邻的2的幂间的偶数块用红色编号① ② ③ ④ ...........表示)

      (紫色数字代表相邻的2的幂间的奇数的个数)

  对于偶数块①:只有一个奇数 3;

  3*21 来到偶数块②;

  3*22 来到偶数块③;

  3*23 来到偶数块④;

  ........

  3*2x-1来到偶数块(x);

  (注意偶数块的编号和2的幂的关系)

  可知,通过3*2可求出P3*21 , P3*22 , .........., P3*2x-1,其集合元素个数总和为 1+2+3+..........+(x-1);

  那么,对于偶数块 2 中的某一奇数 odd 呢?

  根据对3的分析,可知,偶数块②可以构成的 ≤ 2x+1 的最大的偶数为 odd*2x-2 ,那么,通过 odd 求出的集合Podd*2i 的元素个数总和为 1+2+3+.......+(x-2)

  因为偶数块②有21个奇数,所以这些奇数可以求出的集合P的元素个数总和为 2*(1+2+3+........+(x-2) );

  偶数块③有22个奇数,其中任意一个 odd 可构成的 ≤ 2x+1 的最大的偶数为 odd*2x-3 ,这些奇数可以求出的集合P的元素个数总和为 22*(1+2+......+(x-3) );

  ..............

  偶数块(x-1)有2x-2个奇数,其可求出的集合P的元素个数总和为2x-2;

  综上,2x+1 及其之前的偶数乘积最多可以分解出的2的个数为:

  

  这几项加和的值等于 2x+1-1;

  (并不是通过公式化简成这个最简式,而是通过打表找到的,公式化简的话,只能依靠那些大佬了QWQ)

  打表推公式代码:(明天张贴)

 #include<iostream>
#include<cstdio>
using namespace std; int Sum(int pow,int up)
{
int sum=;
for(int i=;i <= up;++i)
sum += i;
return sum*pow;
}
int main()
{
int x;
while(~scanf("%d",&x))
{
int sum=Sum(,x);
int base=;
for(int i=;i <= x-;++i)
{
sum += Sum(base,x--i);
base *= ;
}
printf("sum=%d,%d\n",sum,<<x);
}
}

  那么,如果 e 为2的幂,直接输出 e-1;

  如果不是,先求出 ≤ e 的最大的2的幂 2x+1 ,记录当前答案 ans = 2x+1-1;

  那[2x+1 , e]之间的解该如何求出呢?

  还是考虑 odd*2i 的模式;

  令 odd1 ∈ [ 2x+1 / 2 , e / 2],∀odd1 * 2 ∈ [ 2x+1 , e ],且为 e-prime,ans += tot1*1;(tot为奇数个数)

  令 odd2 ∈ [ 2x+1 / 4 , e / 4],∀odd2 * 4 ∈ [ 2x+1 , e ],且为 e-prime,ans += tot2*2;

  .............

  令 oddk ∈ [ 2x+1 / 2k , e / 2k],∀oddk * 2x ∈ [ 2x+1 , e ],且为 e-prime,ans += totk*k;

  结束的条件是  2x+1 / 2k = e / 2k

AC代码:(C++版大数伪码)(明天张贴)

 #include<iostream>
#include<cstdio>
using namespace std;
#define BigInteger long long BigInteger e;
BigInteger base; BigInteger F()
{
BigInteger curBase=;
BigInteger ans=;
BigInteger l=base/curBase;
BigInteger r=e/curBase;
for(int i=;i < ;++i)
{
// cout<<l<<' '<<r<<endl;
if(l >= r)
break;
BigInteger tmp=(r-l)/;
if(r&)
tmp++;
ans=ans+tmp*i;
l=l/;
r=r/;
}
return ans;
}
void Solve()
{
base=;
while(base* <= e)
base *= ;
BigInteger ans=base-; if(base != e)
ans=ans+F(); cout<<ans<<endl;
}
int main()
{
int test;
while(cin>>test)
{
while(test--)
{
cin>>e;
Solve();
}
}
return ;
}

C++版 BigInteger(逃)

AC代码:(Java BigInteger类)(明天张贴)

 import java.math.BigInteger;
import java.util.Scanner; public class Main { static Scanner cin = new Scanner(System.in);
static BigInteger e,base;
static BigInteger zero=BigInteger.valueOf(0);
static BigInteger one=BigInteger.valueOf(1);
static BigInteger two=BigInteger.valueOf(2);
public static void main(String[] args) { int test;
while(cin.hasNext()) {
test=cin.nextInt();
for(int i=1;i <= test;++i) { e=cin.nextBigInteger();
Solve();
}
}
}
private static void Solve() { base=one;
while(base.multiply(two).compareTo(e) <= 0)
base=base.multiply(two);
// System.out.println(base);
BigInteger ans=base.subtract(one); if(!base.equals(e))
ans=ans.add(F());
System.out.println(ans);
}
private static BigInteger F() { BigInteger curBase=two;
BigInteger ans=zero;
BigInteger l=base.divide(curBase);
BigInteger r=e.divide(curBase);
for(int i=1;i < 4000;++i) { if(l.compareTo(r) >= 0)
break;
BigInteger tmp=(r.subtract(l)).divide(two);
if(r.mod(two).intValue() != 0)
tmp=tmp.add(one);
ans=ans.add(tmp.multiply(BigInteger.valueOf(i))); l=l.divide(two);
r=r.divide(two);
}
return ans;
}
}

今晚比较嗨,比较尽兴;

陪俺家宝宝乘轻轨去市里疯了一圈,返程的路上还做过了一站;

哈哈哈,要一直陪着宝宝啊*_*

The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror) B"Even Number Theory"(找规律???)的更多相关文章

  1. The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)

    http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391 A     Thanks, TuSimple! Time ...

  2. zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)

    题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...

  3. Mergeable Stack 直接list内置函数。(152 - The 18th Zhejiang University Programming Contest Sponsored by TuSimple)

    题意:模拟栈,正常pop,push,多一个merge A B 形象地说就是就是将栈B堆到栈A上. 题解:直接用list 的pop_back,push_back,splice 模拟, 坑:用splice ...

  4. 152 - - G Traffic Light 搜索(The 18th Zhejiang University Programming Contest Sponsored by TuSimple )

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5738 题意 给你一个map 每个格子里有一个红绿灯,用0,1表示 ...

  5. The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack

    题目链接 题意: 题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!! 代码: #include <std ...

  6. The 18th Zhejiang University Programming Contest Sponsored by TuSimple

    Pretty Matrix Time Limit: 1 Second      Memory Limit: 65536 KB DreamGrid's birthday is coming. As hi ...

  7. ZOJ 4016 Mergeable Stack(from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)

    模拟题,用链表来进行模拟 # include <stdio.h> # include <stdlib.h> typedef struct node { int num; str ...

  8. ZOJ 4019 Schrödinger's Knapsack (from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)

    题意: 第一类物品的价值为k1,第二类物品价值为k2,背包的体积是 c ,第一类物品有n 个,每个体积为S11,S12,S13,S14.....S1n ; 第二类物品有 m 个,每个体积为 S21,S ...

  9. The 17th Zhejiang University Programming Contest Sponsored by TuSimple J

    Knuth-Morris-Pratt Algorithm Time Limit: 1 Second      Memory Limit: 65536 KB In computer science, t ...

随机推荐

  1. mysql安装出现问题(The service already exists)

    1.管理员身份运行cmd(系统win10) 2.输入命令cd /d F:\mysql-5.7.19-win32\bin(此为mysql要安装的目录) 3.输入安装命令mysqld install 出现 ...

  2. 获取spring security用户相关信息

    在JSP中获得 使用spring security的标签库 在页面中引入标签 <%@ taglib prefix="sec" uri="http://www.spr ...

  3. Lcd(一)显示原理

    一.LCD控制原理 S5PV210处理器中自带LCD控制器,控制LCD的显示,把 LCD 图像数据从一个位于系统内存的 video buffer 传送到一个外部的 LCD 驱动器接口. 类型: STN ...

  4. c/c++ linux 进程间通信系列2,使用UNIX_SOCKET

    linux 进程间通信系列2,使用UNIX_SOCKET 1,使用stream,实现进程间通信 2,使用DGRAM,实现进程间通信 关键点:使用一个临时的文件,进行信息的互传. s_un.sun_fa ...

  5. 一天一个Linux命令--dhclient

    dhclient -r #用于释放ip地址2 dhclient #获取IP地址 主要针对只有命令行的Linux机器,临时改变了网络环境,事先手动设置的ip地址 看一下自带的解释 root@ubuntu ...

  6. netstat Recv-Q和Send-Q

    通过netstat -anp可以查看机器的当前连接状态:   Active Internet connections (servers and established) Proto Recv-Q Se ...

  7. canvas如何自适应屏幕大小

    可以用JS监控屏幕大小,然后调整Canvas的大小.在代码中加入JS $(window).resize(resizeCanvas);  function resizeCanvas() {        ...

  8. day21-多并发编程基础(二)

    今日要整理的内容有 1. 操作系统中线程理论 2.python中的GIL锁 3.线程在python中的使用 开始今日份整理 1. 操作系统中线程理论 1.1 线程引入背景 之前我们已经了解了操作系统中 ...

  9. 【vue】vue全家桶

    vue-router(http://router.vuejs.org) vuex(https://vuex.vuejs.org/zh/guide/) vue-resource(https://gith ...

  10. python3 闭包函数

    '''闭包函数:内部函数引用外部函数变量(非全局变量)'''def func(y): x = 1 def func1(): print(x, y) return func1 f = func(2)pr ...