sgu 169 Numbers

题意:n和n+1同时被数位乘积整除的k位数个数。

假如a是237,b是238。由于个位以前的数一样。那么对于2,如果a%2==0,b%2就!=0,如果a%3==0,b%3就!=0。因此个位以前的数只能是1.再列举个位的情况。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#define mkp make_pair
using namespace std;
const double EPS=1e-8;
const int SZ=20,INF=0x7FFFFFFF;
typedef long long lon;
int arr[SZ];

bool chk(const vector<int> &vct,int mod)
{
    if(mod==1||mod==2||mod==5)return 1;
    else if(mod==3||mod==9)return (vct.size()-1)%mod==0;
    else if(mod==6)return (vct.size()-1)%3==0;
    else
    {
        int res=0;
        for(int i=0;i<vct.size();++i)
        {
            res=res*10+vct[i];
            res%=mod;
        }
        return res==0;
    }
}

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    //cin>>casenum;
    //for(lon time=1;time<=casenum;++time)
    {
        int n;
        cin>>n;
        vector<int> vct(n,1);
        for(int i=1;i<10;++i)
        {
            vct[n-1]=i;
            if(chk(vct,i))arr[i]=1;
        }
        int res=0;
        for(int i=1;i<9;++i)
        {
            if(arr[i]&&arr[i+1])++res;
        }
        cout<<res<<endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/gaudar/p/9789195.html

时间: 2024-08-30 14:08:10

sgu 169 Numbers的相关文章

SGU 169 numbers 数学

169.Numbers Let us call P(n) - the product of all digits of number n (in decimal notation). For example, P(1243)=1*2*4*3=24; P(198501243)=0. Let us call n to be a good number, if (p(n)<>0) and (n mod P(n)=0). Let us call n to be a perfect number, if

SGU 169 Numbers (找规律)

题意:中文题,直接忽略... 析:先说说我的思路,我一看这个题第一感觉就是要找规律,要是挨着算,猴年马月都跑不完,更何况时间限制是0.25s,怎么找规律呢,我算了一下前10位,分别是8,1,1,3,1,1,4,1,1,3,然后我就觉得应该是113114循环再加一第一位是8,果然AC了. 然后结束后我看看了题解好像是算出来的,因为数很大又不是高精度,肯定是要找规律了,假设n有k位,分别从右往左a1,a2...ak,首先a1(也就是个位)肯定不是9(因为如果是9,那么n+1就有0了),所以呢n+1各

SGU[113] Nearly prime numbers

Description 描述 Nearly prime number is an integer positive number for which it is possible to find such primes P1 and P2 that given number is equal to P1*P2. There is given a sequence on N integer positive numbers, you are to write a program that prin

SGU 258 Almost Lucky Numbers 接近幸运数(数位DP)

题意: 定义一个具有2n位的正数,其前n位之和与后n位之和相等,则为lucky数.给定一个区间,问有多少个正数可以通过修改某一位数从而变成lucky数?注意不能含前导0. 思路: 我的想法是记录那些非lucky数,再想办法来统计,后来发现有点行不通,无法知道其前后部之和是否相等.如果记录lucky数,然后通过统计每个位上的数来变成lucky数,这更麻烦,因为会重复统计,比如11和22是lucky数,而21可以通过修改1位来变成lucky数,被统计了两次. 学习了前辈的方法,也强迫一下自己别人的模

Nearly prime numbers - SGU 113(素数)

题目大意:判断一个数是否是两个素数的乘积,如果是,输出Yes,否则No. 分析:先打表求出来一部分素因子,用素数对素数判定还是比较快的. 代码如下: =============================================================================================================================== #include<stdio.h> #include<algorithm> #i

【SGU 390】Tickets (数位DP)

Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell tickets to the passengers. So no wonder that once upon a time in a faraway galaxy one conductor decided to diversify this occupation. Now this conductor

SGU 112 a^b-b^a

JAVA大数.... a^b-b^a Time Limit: 250MS   Memory Limit: 4096KB   64bit IO Format: %I64d & %I64u [Submit]   [Go Back]   [Status] Description You are given natural numbers a and b. Find ab-ba. Input Input contains numbers a and b (1≤a,b≤100). Output Write

1100. Mars Numbers (20)

People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, respectively. For the next higher dig

SGU 242. Student&#39;s Morning( 网络流 )

看英文题真是麻烦...理解题意花的时间比想的时间还长...裸的网络流, 我们只要限制每个人出发流量为1, 每个大学进入的流量至多为2即可, 相当于构造可行解. ---------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<cctype&