zoukankan      html  css  js  c++  java
  • HDU 1333 基础数论 暴力

    定义一种数位simth数,该数的各位之和等于其所有质因子所有位数字之和,现给出n求大于n的最小该种数,n最大不超过8位,那么直接暴力就可以了。

    /** @Date    : 2017-09-08 14:12:08
      * @FileName: HDU 1333 素因子 暴力.cpp
      * @Platform: Windows
      * @Author  : Lweleth (SoungEarlf@gmail.com)
      * @Link    : https://github.com/
      * @Version : $Id$
      */
    #include <bits/stdc++.h>
    #define LL long long
    #define PII pair<int ,int>
    #define MP(x, y) make_pair((x),(y))
    #define fi first
    #define se second
    #define PB(x) push_back((x))
    #define MMG(x) memset((x), -1,sizeof(x))
    #define MMF(x) memset((x),0,sizeof(x))
    #define MMI(x) memset((x), INF, sizeof(x))
    using namespace std;
    
    const int INF = 0x3f3f3f3f;
    const int N = 1e5+20;
    const double eps = 1e-8;
    
    LL pri[N];
    LL sum[N];
    bool vis[N];
    int c = 0;
    void prime()
    {
    	MMF(vis);
    	MMF(sum);
    	for(int i = 2; i < N; i++)
    	{
    		if(!vis[i])
    		{
    			pri[c++] = i;
    			LL t = i;
    			while(t)
    				sum[c - 1] += t % 10, t /= 10;
    		}
    		for(int j = 0; j < c && i * pri[j] < N; j++)
    		{
    			vis[i * pri[j]] = 1;
    			if(i % pri[j] == 0) break;
    		}
    	}
    }
    
    int main()
    {
    	prime();
    	LL n;
    	while(cin >> n && n)
    	{
    		for(int i = n + 1; ;i++)
    		{
    			LL tmp = i;
    			LL a = 0;
    			while(tmp)
    				a += tmp % 10, tmp /= 10;
    
    			LL b = 0;
    			LL t = i;
    			for(int j = 0; j < c && pri[j] * pri[j] <= t; j++)
    			{
    				if(t % pri[j] == 0)
    				{
    					while(t % pri[j] == 0)
    						t /= pri[j], b+=sum[j];
    				}
    			}
    			if(t != i && t > 1) 
    				while(t)
    					b += t % 10, t/= 10;
    			if(b == a)
    			{
    				printf("%lld
    ", i);
    				break;
    			}
    		}
    	}
        return 0;
    }
  • 相关阅读:
    浏览器检测
    EcmaScript基础
    js中的内置对象
    cursor 与refcursor及sys_refcursor的区别 (转载)
    各种连接数据方法的网站
    UVa11627 Slalom
    UVa1450 Airport
    UVa12124 Assemble
    UVa11384 Help is needed for Dexter
    UVa11464 Even Parity
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/7496434.html
Copyright © 2011-2022 走看看