Wonderprime Brands

本文介绍了一种特殊类型的素数——Wonderprimes,这类素数可以被分割为两个至少包含D位数的素数部分。文章提供了查找首个大于或等于给定整数N的Wonderprime的算法实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

The cows are forever competing to see who has the best brand. The latest rage is brands that are ‘Wonderprimes’. You probably already know that a brand consists of a sequence of digits that does not begin with 0; brands actually look a lot like positive integers.
A wonderprime is a number that can be partitioned into two prime numbers, each of which has at least D digits and, of course, doesn’t start with 0. When D=2, the number 11329 is a wonderprime (since it connects 113 and 29, both of which are prime).
Only a few of the cows have wonderprime brands, but they all want one. Your job is to find the first wonderprime greater than or equal to a supplied integer N (1 <= N <= 2,000,000,000). No integer greater than 2,000,000,000 will be required.

Input

Line 1: Two space-separated integers: D and N

Output

Line 1: A line that contains the first wonderprime no smaller than N.

Example Input

2 11328

Example Output

11329

Solution

纯枚举

#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll d, n, mod(10), minimum(1);

bool prime(ll x);

bool iskey(ll x);

int main()
{
    scanf("%lld%lld", &d, &n);
    for (ll i = 1; i < d; i++) { mod *= 10; minimum *= 10; }
    if (n < mod * minimum) n = mod * minimum;
    while (!iskey(n)) n++;
    printf("%lld\n", n);;
    
    return 0;
}

bool prime(ll x)
{
    if (x < 2) return false;
    for (ll i = 2; i * i <= x; i++)
        if (x % i == 0) return false;
    return true;
}

bool iskey(ll n)
{
    ll x = n / mod, y = n % mod, pow = mod;
    if (n % mod / minimum)
        if (prime(x) && prime(y))
            return true;
    y += x % 10 * pow; x /= 10;
    while (x >= minimum)
    {
        if (y >= pow)
        {
            if (prime(x) && prime(y))
                return true;
        }
        pow *= 10;
        y += x % 10 * pow; x /= 10;
    }
    return false;
}
### 修改 WordPress 中 Brands 的方法 在 WordPress 中,“Brands”通常被实现为一种自定义文章类型(Custom Post Type)。要修改这种类型的设置或行为,可以通过多种方式完成,比如调整其注册参数、添加新字段或者通过钩子扩展功能。 #### 1. 调整已有的 Brands 文章类型 如果 Brands 已经作为自定义文章类型存在,则可以使用 `register_post_type_args` 过滤器来动态修改该文章类型的属性。以下是具体代码示例: ```php function modify_brands_post_type( $args, $post_type ) { if ( 'brands' === $post_type ) { // 更改标签 $args['labels']->name = 'Brand Names'; // 添加支持的功能 $args['supports'] = array('title', 'editor', 'thumbnail'); // 设置菜单图标 $args['menu_icon'] = 'dashicons-admin-site-alt'; } return $args; } add_filter( 'register_post_type_args', 'modify_brands_post_type', 10, 2 ); ``` 上述代码会更新 Brands 类型的名称、支持的功能以及菜单图标[^3]。 #### 2. 扩展 Brands 功能 为了给 Brands 增加额外的功能,例如自定义元数据字段,可以利用 Meta Box 或 Advanced Custom Fields 插件创建新的字段组。这些工具能够帮助开发者轻松管理品牌的相关信息,如 Logo 图片、描述文字等[^2]。 另外,也可以手动编写代码向数据库存储附加的数据项。下面是一个简单的例子展示如何保存并显示品牌详情页上的额外信息: ```php // 保存自定义字段值 function save_brand_meta_fields($post_id) { if (isset($_POST['brand_website'])) { update_post_meta($post_id, '_brand_website', sanitize_text_field($_POST['brand_website'])); } } add_action('save_post_brands', 'save_brand_meta_fields'); // 显示前端内容 function display_brand_website_link() { global $post; if ('brands' !== get_post_type()) return; $website_url = get_post_meta($post->ID, '_brand_website', true); if (!empty($website_url)) { echo '<p><strong>Website:</strong> <a href="' . esc_url($website_url) . '" target="_blank">' . esc_html($website_url) . '</a></p>'; } } add_action('the_content', 'display_brand_website_link'); ``` 这段脚本实现了两个主要目标:一是当编辑某个 Brand 条目时允许输入网站链接;二是确保这个链接能在前台正常呈现出来[^4]。 #### 3. 配置 REST API 支持 为了让 Brands 可以通过 WordPress 提供的标准 RESTful 接口访问到,需确认它们已经启用了相应的选项。如果没有默认开启的话,可通过如下函数激活它: ```php function enable_rest_api_for_brands() { register_rest_route( 'myplugin/v1', '/brands/(?P<id>\d+)', [ 'methods' => WP_REST_Server::READABLE, 'callback' => function ($data) { return get_post((int)$data['id']); }, ] ); } add_action('rest_api_init', 'enable_rest_api_for_brands'); ``` 这样做的好处在于第三方应用能更容易集成进来获取所需的品牌资料。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值