zoukankan      html  css  js  c++  java
  • 1.2杰哥和数字

    题目

    题意:求一个数字的因子中,有多少个因子,是符合与原数字有相同数字的数的

    思路:先把原数字拆开,村在数组里,写一个判断的函数,输入一个数字,就可以返回和原来的数字是不是有相同数字。在for一边,从1到根号n,看看有哪些是n的因子,然后这样看的时候,也看看另一个因子是不是符合条件,注意,比如输入100,它的因子有10*10,这时候如果两个因子相同就只要判断一次就好了

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include <iomanip>
    #include<cmath>
    #include<float.h> 
    #include<string.h>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #define sf scanf
    #define pf printf
    #define scf(x) scanf("%d",&x)
    #define scff(x,y) scanf("%d%d",&x,&y)
    #define prf(x) printf("%d
    ",x) 
    #define mm(x,b) memset((x),(b),sizeof(x))
    #define rep(i,a,n) for (int i=a;i<n;i++)
    #define per(i,a,n) for (int i=a;i>=n;i--)
    typedef long long ll;
    const ll mod=1e9+7;
    const double eps=1e-8;
    const int inf=0x3f3f3f3f;
    using namespace std;
    const double pi=acos(-1.0);
    const int N=1e5+12;
    int sum[10];
    void init(int n)    //先把这个数字的每一位拆开,村在sum数组里
    {
    	mm(sum,0);
    	{
    		sum[n%10]++;
    		n/=10;
    	}
    }
    int judge(int n)    //判断这个数字和原来的数字有没有相同的
    {
    	while(n)
    	{
    		if(sum[n%10])
    		    return 1;
    		n/=10;
    	}
    	return 0;
    }
    int main()
    {
    	int n;
    	scf(n);
    	if(n==1)
    	{
    		pf("1");
    		return 0;
    	 } 
    	init(n);
    	int ans=1;        //自己一定符合条件,所以答案从一开始
    	for(int i=1;i*i<=n;i++)
    	{
    		if(n%i==0)
    		{
    			if(judge(i))
    			    ans++;
    			if(n/i!=i)        //判断另一个因子符合嘛,如果i*i等于n的时候,就只会判断一次
    			    if(judge(n/i))
    			ans++;
    		}
    	}
    	prf(ans);
    	return 0;
    }
    
  • 相关阅读:
    7.13dfs例题:部分和
    7.12dfs例题:数独游戏
    1.2题解:如何找数组中唯一成对的那个数(位运算)
    左程云Java算法(1)
    SQL基本语句增删改查
    Python spyder Ipython console 连接失败问题
    VBA——Msgbox
    python 字符串
    Scrapy-selectors总结
    文字单行居中,多行居左/居右
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/10043155.html
Copyright © 2011-2022 走看看