project euler 32

Problem 32


Pandigital products

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.

The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.

Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.

HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.


全数字的乘积

如果一个n位数包含了1至n的所有数字恰好一次,我们称它为全数字的;例如,五位数15234就是1至5全数字的。

7254是一个特殊的乘积,因为在等式39 × 186 = 7254中,被乘数、乘数和乘积恰好是1至9全数字的。

找出所有被乘数、乘数和乘积恰好是1至9全数字的乘法等式,并求出这些等式中乘积的和。

注意:有些乘积可能从多个乘法等式中得到,但在求和的时候只计算一次。

package projecteuler;

import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

public class Prj32 {

	/**
	 * We shall say that an n-digit number is pandigital if it makes use of all
	 * the digits 1 to n exactly once; for example, the 5-digit number, 15234,
	 * is 1 through 5 pandigital.
	 * 
	 * The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing
	 * multiplicand, multiplier, and product is 1 through 9 pandigital.
	 * 
	 * Find the sum of all products whose multiplicand/multiplier/product
	 * identity can be written as a 1 through 9 pandigital.
	 * 
	 * HINT: Some products can be obtained in more than one way so be sure to
	 * only include it once in your sum.
	 */
	@Test
	public void test() {
		// System.out.println(9 * 9999);
		// System.out.println(10 * 999);
		// System.out.println(99 * 999);
		System.out.println(Calculator.calculate());
	}

	public static class Calculator {

		/**
		 * a + b + c = 9; a = 1 && b = 4; a = 2 && b = 3;
		 * 
		 * @return
		 */
		public static int calculate() {

			int a = 0;
			int b = 0;
			Set<Integer> set = new HashSet<Integer>();
			for (a = 1; a <= 10; a++) {
				for (b = 1000; b <= 10000; b++) {
					if (checkNum(a, b, a * b)) {
						System.out.println(a + "*" + b + "=" + a * b);
						set.add(a * b);
					}
				}
			}

			for (a = 10; a <= 100; a++) {
				for (b = 100; b <= 1000; b++) {
					if (checkNum(a, b, a * b)) {
						System.out.println(a + "*" + b + "=" + a * b);
						set.add(a * b);
					}
				}
			}

			int sum = 0;
			for (Integer intVal : set) {
				sum += intVal;

			}

			return sum;
		}

		public static boolean checkNum(int a, int b, int c) {
			Set<Integer> set = new HashSet<Integer>();
			int val = a;
			while (val >= 10) {
				if (set.contains(val % 10)) {
					return false;
				}
				set.add(val % 10);
				val /= 10;
			}
			if (set.contains(val)) {
				return false;
			}
			set.add(val);
			val = b;
			while (val >= 10) {
				if (set.contains(val % 10)) {
					return false;
				}
				set.add(val % 10);
				val /= 10;
			}
			if (set.contains(val)) {
				return false;
			}
			set.add(val);
			val = c;
			while (val >= 10) {
				if (set.contains(val % 10)) {
					return false;
				}
				set.add(val % 10);
				val /= 10;
			}
			if (set.contains(val)) {
				return false;
			}
			set.add(val);
			return set.size() == 9 && set.contains(1) && set.contains(2)
					&& set.contains(3) && set.contains(4) && set.contains(5)
					&& set.contains(6) && set.contains(7) && set.contains(8)
					&& set.contains(9);
		}

	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在openeuler上安装OpenStack的步骤: 1. 确保你的openeuler系统已经安装了必要的软件包和依赖项。可以使用以下命令安装: ```shell sudo dnf install -y python3-devel libffi-devel gcc openssl-devel ``` 2. 添加OpenStack Train软件源。可以使用以下命令添加: ```shell sudo dnf install -y centos-release-openstack-train ``` 3. 安装OpenStack客户端和服务组件。可以使用以下命令安装: ```shell sudo dnf install -y python3-openstackclient openstack-selinux openstack-utils ``` 4. 配置数据库。可以使用以下命令安装MariaDB数据库: ```shell sudo dnf install -y mariadb mariadb-server python3-PyMySQL ``` 然后启动MariaDB服务并设置开机自启: ```shell sudo systemctl enable mariadb.service sudo systemctl start mariadb.service ``` 接下来,使用以下命令来配置MariaDB数据库: ```shell sudo mysql_secure_installation ``` 5. 配置消息队列。可以使用以下命令安装RabbitMQ消息队列: ```shell sudo dnf install -y rabbitmq-server ``` 然后启动RabbitMQ服务并设置开机自启: ```shell sudo systemctl enable rabbitmq-server.service sudo systemctl start rabbitmq-server.service ``` 6. 配置身份认证服务。可以使用以下命令安装Keystone身份认证服务: ```shell sudo dnf install -y openstack-keystone httpd mod_wsgi ``` 然后启动httpd服务并设置开机自启: ```shell sudo systemctl enable httpd.service sudo systemctl start httpd.service ``` 7. 配置计算服务。可以使用以下命令安装Nova计算服务: ```shell sudo dnf install -y openstack-nova-api openstack-nova-conductor \ openstack-nova-console openstack-nova-novncproxy \ openstack-nova-scheduler python3-novaclient ``` 8. 配置网络服务。可以使用以下命令安装Neutron网络服务: ```shell sudo dnf install -y openstack-neutron openstack-neutron-ml2 \ openstack-neutron-linuxbridge ebtables ipset ``` 9. 配置镜像服务。可以使用以下命令安装Glance镜像服务: ```shell sudo dnf install -y openstack-glance ``` 10. 配置块存储服务。可以使用以下命令安装Cinder块存储服务: ```shell sudo dnf install -y openstack-cinder targetcli python-keystone ``` 11. 配置对象存储服务。可以使用以下命令安装Swift对象存储服务: ```shell sudo dnf install -y openstack-swift-proxy python3-swiftclient \ python3-keystoneclient python3-keystonemiddleware \ python3-eventlet xfsprogs rsync ``` 12. 配置Dashboard服务。可以使用以下命令安装Horizon Dashboard服务: ```shell sudo dnf install -y openstack-dashboard ``` 13. 配置OpenStack服务。可以使用以下命令配置OpenStack服务: ```shell sudo openstack-config --set /etc/nova/nova.conf database connection mysql+pymysql://nova:password@controller/nova sudo openstack-config --set /etc/nova/nova.conf DEFAULT transport_url rabbit://openstack:password@controller sudo openstack-config --set /etc/nova/nova.conf api auth_strategy keystone sudo openstack-config --set /etc/nova/nova.conf keystone_authtoken www_authenticate_uri http://controller:5000 sudo openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_url http://controller:5000 sudo openstack-config --set /etc/nova/nova.conf keystone_authtoken memcached_servers controller:11211 sudo openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_type password sudo openstack-config --set /etc/nova/nova.conf keystone_authtoken project_domain_name Default sudo openstack-config --set /etc/nova/nova.conf keystone_authtoken user_domain_name Default sudo openstack-config --set /etc/nova/nova.conf keystone_authtoken project_name service sudo openstack-config --set /etc/nova/nova.conf keystone_authtoken username nova sudo openstack-config --set /etc/nova/nova.conf keystone_authtoken password password sudo openstack-config --set /etc/nova/nova.conf DEFAULT my_ip 10.0.0.11 sudo openstack-config --set /etc/nova/nova.conf DEFAULT use_neutron True sudo openstack-config --set /etc/nova/nova.conf DEFAULT firewall_driver nova.virt.firewall.NoopFirewallDriver sudo openstack-config --set /etc/nova/nova.conf vnc enabled true sudo openstack-config --set /etc/nova/nova.conf vnc server_listen 0.0.0.0 sudo openstack-config --set /etc/nova/nova.conf vnc server_proxyclient_address \$my_ip sudo openstack-config --set /etc/nova/nova.conf vnc novncproxy_base_url http://controller:6080/vnc_auto.html sudo openstack-config --set /etc/nova/nova.conf glance api_servers http://controller:9292 sudo openstack-config --set /etc/nova/nova.conf oslo_concurrency lock_path /var/lib/nova/tmp sudo openstack-config --set /etc/neutron/neutron.conf database connection mysql+pymysql://neutron:password@controller/neutron sudo openstack-config --set /etc/neutron/neutron.conf DEFAULT transport_url rabbit://openstack:password@controller sudo openstack-config --set /etc/neutron/neutron.conf DEFAULT auth_strategy keystone sudo openstack-config --set /etc/neutron/neutron.conf keystone_authtoken www_authenticate_uri http://controller:5000 sudo openstack-config --set /etc/neutron/neutron.conf keystone_authtoken auth_url http://controller:5000 sudo openstack-config --set /etc/neutron/neutron.conf keystone_authtoken memcached_servers controller:11211 sudo openstack-config --set /etc/neutron/neutron.conf keystone_authtoken auth_type password sudo openstack-config --set /etc/neutron/neutron.conf keystone_authtoken project_domain_name Default sudo openstack-config --set /etc/neutron/neutron.conf keystone_authtoken user_domain_name Default sudo openstack-config --set /etc/neutron/neutron.conf keystone_authtoken project_name service sudo openstack-config --set /etc/neutron/neutron.conf keystone_authtoken username neutron sudo openstack-config --set /etc/neutron/neutron.conf keystone_authtoken password password sudo openstack-config --set /etc/neutron/neutron.conf oslo_concurrency lock_path /var/lib/neutron/tmp sudo openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:password@controller/glance sudo openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://controller:5000 sudo openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://controller:5000 sudo openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers controller:11211 sudo openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password sudo openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default sudo openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default sudo openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service sudo openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance sudo openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password password sudo openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone sudo openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http sudo openstack-config --set /etc/glance/glance-api.conf glance_store default_store file sudo openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/ sudo openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:password@controller/glance sudo openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://controller:5000 sudo openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://controller:5000 sudo openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers controller:11211 sudo openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type password sudo openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name Default sudo openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name Default sudo openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service sudo openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance sudo openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password password sudo openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone sudo openstack-config --set /etc/cinder/cinder.conf database connection mysql+pymysql://cinder:password@controller/cinder sudo openstack-config --set /etc/cinder/cinder.conf DEFAULT transport_url rabbit://openstack:password@controller sudo openstack-config --set /etc/cinder/cinder.conf DEFAULT auth_strategy keystone sudo openstack-config --set /etc/cinder/cinder.conf keystone_authtoken www_authenticate_uri http://controller:5000 sudo openstack-config --set /etc/cinder/cinder.conf keystone_authtoken auth_url http://controller:5000 sudo openstack-config --set /etc/cinder/cinder.conf keystone_authtoken memcached_servers controller:11211 sudo openstack-config --set /etc/cinder/cinder.conf keystone_authtoken auth_type password sudo openstack-config --set /etc/cinder/cinder.conf keystone_authtoken project_domain_name Default sudo openstack-config --set /etc/cinder/cinder.conf keystone_authtoken user_domain_name Default sudo openstack-config --set /etc/cinder/cinder.conf keystone_authtoken project_name service sudo openstack-config --set /etc/cinder/cinder.conf keystone_authtoken username cinder sudo openstack-config --set /etc/cinder/cinder.conf keystone_authtoken password password sudo openstack-config --set /etc/cinder/cinder.conf oslo_concurrency lock_path /var/lib/cinder/tmp sudo openstack-config --set /etc/swift/proxy-server.conf DEFAULT bind_port 8080 sudo openstack-config --set /etc/swift/proxy-server.conf DEFAULT user swift sudo openstack-config --set /etc/swift/proxy-server.conf DEFAULT swift_dir /etc/swift sudo openstack-config --set /etc/swift/proxy-server.conf pipeline:main pipeline "catch_errors healthcheck cache authtoken keystoneauth proxy-server" sudo openstack-config --set /etc/swift/proxy-server.conf filter:keystoneauth use "egg:swift#keystoneauth" sudo openstack-config --set /etc/swift/proxy-server.conf filter:keystoneauth operator_roles admin,user sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken paste.filter_factory keystonemiddleware.auth_token:filter_factory sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken auth_uri http://controller:5000 sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken auth_url http://controller:5000 sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken memcached_servers controller:11211 sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken auth_type password sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken project_domain_name Default sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken user_domain_name Default sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken project_name service sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken username swift sudo openstack-config --set /etc/swift/proxy-server.conf filter:authtoken password password sudo openstack-config --set /etc/swift/proxy-server.conf filter:cache use "egg:swift#memcache" sudo openstack-config --set /etc/swift/proxy-server.conf filter:cache memcache_servers controller:11211 sudo openstack-config --set /etc/swift/proxy-server.conf filter:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值