bzoj3034: Heaven Cow与God Bull

Description

__int64 ago,there‘s a heaven cow called sjy...
A god bull named wzc fell in love with her...
As an OI & MOer,wzc gave sjy a quesiton...

给定一个整数n,求一个整数m,满足m<=n,并且m/phi(m)的值最大。
注:phi(m)代表m的欧拉函数,即不大于m且与m互质的数的个数。

Input

第一行是一个整数T,表示该测试点有T组数据。
接下来T行,每行一个整数n,意义如上所述。

Output

输出一共T行,每行一个整数m。
若对于某个n,有不止一个满足条件的m,则输出最小的m。

贪心考虑,答案为质数的前缀积,筛出60000以内的质数,离线处理询问

高精度需要压位优化

#include<cstdio>
#include<cstring>
int ps[60000],pp=0;
bool isnp[60004];
int T;
char str[30000];
int p10[]={1,10,100,1000};
struct integer{
    int x[7000],id,ed;
    void read(){
        scanf("%s",str);
        int l=strlen(str)-1;
        for(int i=0;i<=l;i++){
            x[i>>2]+=p10[i&3]*(str[l-i]-‘0‘);
        }
    }
    void print(){
        int p=6999;
        while(p&&!x[p])--p;
        printf("%d",x[p]);
        for(int i=p-1;~i;--i)printf("%04d",x[i]);
        putchar(10);
    }
    void operator*=(int a){
        for(int i=0;i<7000;i++)x[i]*=a;
        for(int i=0;i<6999;i++)x[i+1]+=x[i]/10000,x[i]%=10000;
    }
}q[100],v,v1;
bool operator>(integer&a,integer&b){
    for(int i=6999;~i;--i){
        if(a.x[i]!=b.x[i])return a.x[i]>b.x[i];
    }
    return 0;
}
int main(){
    for(int i=2;i<=60000;i++){
        if(!isnp[i])ps[pp++]=i;
        for(int j=0;j<pp&&i*ps[j]<=60000;j++){
            isnp[i*ps[j]]=1;
            if(i%ps[j]==0)break;
        }
    }
    scanf("%d",&T);
    for(int i=0;i<T;i++){
        q[i].id=i;
        q[i].read();
    }
    v.x[0]=v1.x[0]=1;
    for(int i=0;i<pp;i++){
        v*=ps[i];
        for(int j=0;j<T;j++)if(!q[j].ed&&v>q[j]){
            q[j]=v1;
            q[j].ed=1;
        }
        v1=v;
    }
    for(int i=0;i<T;i++){
        for(int j=0;j<T;j++)if(q[j].id==i){
            q[j].print();
        }
    }
    return 0;
}
时间: 2024-08-25 06:57:35

bzoj3034: Heaven Cow与God Bull的相关文章

「Poetize3」Heaven Cow与God Bull

描述 Description 给定一个整数n,求一个整数m,满足m<=n,并且m/phi(m)的值最大.注:phi(m)代表m的欧拉函数,即不大于m且与m互质的数的个数. 题解:m/phi(m) 很容易化成 连积(p/(p-1))  p|m所以就很简单了,将最小的质数乘起来,直到>n,输出前一个.因为保证最小所以只乘一次,因为p/(p-1)单调减,所以从小的开始选.高精度写错搞了好久,然后有卡了几次时才过了代码: 1 #include<cstdio> 2 3 #include<

tyvj 1934 高精度

「Poetize3」Heaven Cow与God Bull From wwwwodddd 背景 Background __int64 ago,there's a heaven cow called sjy...A god bull named wzc fell in love with her...As an OI & MOer,wzc gave sjy a quesiton... 描述 Description 给定一个整数n,求一个整数m,满足m<=n,并且m/phi(m)的值最大.注:p

BootStrap下拉框搜索功能

<!DOCTYPE html> <html> <head> <title>jQuery bootstrap-select可搜索多选下拉列表插件-www.daimajiayuan.com</title> <script type="text/javascript" src="http://www.daimajiayuan.com/download/jquery/jquery-1.10.2.min.js"

Leetcode刷题第三期Week1——模拟

题目列表来自yxc大佬的AcWing Leetcode提高班第三期 Leetcode 263 Ugly Number 注意:特别地,1是Ugly Number 没什么要注意的,三个循环搞定 class Solution { public: bool isUgly(int num) { if(num <= 0) return false; while(num % 2 == 0) num = num / 2; while(num % 3 == 0) num = num / 3; while(num

Bull And Cows

package cn.edu.xidian.sselab.hashtable; import java.util.HashMap;import java.util.Map;import java.util.Set; /** *  * @author zhiyong wang  * title: Bull And Cows * content: * ou are playing the following Bulls and Cows game with your friend: You writ

poj3278Catch That Cow

Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 88361   Accepted: 27679 Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,00

The Cow Lineup_找规律

Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1...K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds: 1 5 3 2 5 1 3 4 4

poj 1985 Cow Marathon 【树的直径】

题目:poj 1985 Cow Marathon 题意:给出一个树,让你求树的直径. 分析: 树的直径:树上两点之间的最大距离. 我们从任意一点出发,BFS一个最远距离,然后从这个点出发,在BFS一个最远距离,就是树的直径. AC代码: /* POJ:1985 Cow Marathon 2014/10/12/21:18 Yougth*/ #include <cstdio> #include <iostream> #include <algorithm> #include

POJ 2018 Best Cow Fences

斜率优化DP...<浅谈数形结合思想在信息学竞赛中的应用 安徽省芜湖一中 周源>例题... Best Cow Fences Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9311   Accepted: 2986 Description Farmer John's farm consists of a long row of N (1 <= N <= 100,000)fields. Each field c