AtCoder Beginner Contest 336 E题解

发布时间:2024年01月21日

Problem Statement

The?digit sum?of a positive integer?�n?is defined as the sum of the digits in the decimal notation of?�n. For example, the digit sum of?20242024?is?2+0+2+4=82+0+2+4=8.
A positive integer?�n?is called a?good integer?when?�n?is divisible by its digit sum. For example,?20242024?is a good integer because it is divisible by its digit sum of?88.
You are given a positive integer?�N. How many good integers are less than or equal to?�N?

Constraints

  • 1≤�≤10141≤N≤1014
  • �N?is an integer.

Input

The input is given from Standard Input in the following format:

�N

Output

Print the number of good integers less than or equal to?�N.


Sample Input 1Copy

Copy

20

Sample Output 1Copy

Copy

13

There are?1313?good integers less than or equal to?2020:?1,2,3,4,5,6,7,8,9,10,12,18,201,2,3,4,5,6,7,8,9,10,12,18,20.


Sample Input 2Copy

Copy

2024

Sample Output 2Copy

Copy

409

Sample Input 3Copy

Copy

9876543210

Sample Output 3Copy

Copy

547452239

时间超限!

暴搜

int转string

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
signed main()
{
	unsigned long long n,sss=0;
	cin>>n;
	unsigned long long ttt=0;
	for(unsigned long long i=1; i<=n; i++)
		{
			string iss=std::to_string(i);
			
			for(unsigned long long j=0; j<iss.length(); j++)
				{
					ttt=ttt+iss[j]-48;
				}
			if(i%ttt==0)
				{
					sss++;
				}
			ttt=0;
		}
	cout<<sss;
	return 0;
}

文章来源:https://blog.csdn.net/2301_76204446/article/details/135726138
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。