Codeforces 10C Digital Root 规律题

题目链接:点击打开链接

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<set>
#include<vector>
#include<map>
#include<math.h>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 1000005
#define ll __int64
ll num[10],n;
ll go(ll x){
	ll ans = x;
	while(ans>=10){
		ans = 0;
		while(x) {
			ans += x%10;
			x /= 10;
		}
		x = ans;
	}
	return ans;
}
int main(){
	ll i,j,k;
	while(~scanf("%I64d",&n))
	{
		memset(num, 0, sizeof num);
		ll ans = 0;
		for(i=1;i<=n;i++)	num[go(i)]++, ans -= n/i;

		for(j=0;j<10;j++)
			for(k=0;k<10;k++)
				ans+=num[k]*num[j]*num[go(k*j)];
		printf("%I64d\n",ans);
	}
	return 0;
}
/*
2
1 2
3
1 2 3

*/

Codeforces 10C Digital Root 规律题

时间: 2024-08-27 05:30:45

Codeforces 10C Digital Root 规律题的相关文章

CodeForces 10C. Digital Root

求A,B,C ∈[1,N] && A*B != C,d(A*B) == d(C)的组数. 首先要知道d(x) = (x%9 == 0 ? 9 : x%9); 那么则会有A*B == C,则必有d(A*B) == d(C). 若不考虑A*B != C,则答案既是ans[x]*ans[y]*ans[d(x*y)],ans[x]为d(i) == x的个数,显然x∈[1,9]. 当考虑A*B != C时,则需要从ans[x]*ans[y]*ans[d(x*y)] - sum. sum = sigm

Codeforces 10C Digital Root 法冠军

主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<string> #include<stdlib.h> #include<algorithm> using nam

Codeforces 480B Long Jumps 规律题

题目链接:点击打开链接 题意: 输出n l x y 有一根直尺长度为l 上面有n个刻度. 下面n个数字是距离开头的长度(保证第一个数字是0,最后一个数字是l) 要使得 直尺中存在某2个刻度的距离为x , 某2个刻度的距离为y 要添加最少几个刻度. 问: 最少的刻度个数 输出标记的位置. 思路: 分类讨论一下.. 若本身尺子里就有x.y就输出0 若只有x 或只有y就输出一个刻度. 若2个都没有就: 1.加1个刻度ans,这个ans是距离某个刻度距离为x的,然后看一下是否有距离ans为y的刻度,若有

CodeForces 42C Safe cracking 规律题

题目链接:点击打开链接 3个数为一组,找最大的一个数让它降低,则显然是有解的,分类讨论一下就可以 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<vector> using namespace std; int n, k; int a[4]; vector<pair<int,int> >ans; int m

CodeForces 468A 24 Game 规律题

给定一个n表示有n个数字[1,n] 问: 用+ - * 3种运算把n个数变成24是否可行,若可行输出任意解. 思路: 因为2*3*4 = 24; 所以当n>=4时一定有解. 若n是偶数则4个连续数一组消成0,若还多余2个则变成 (n+1)-n = 1. 若n是奇数则把5消掉: 5-1 = 4; 4-2 = 2;. [java] view plaincopy import java.io.PrintWriter; import java.util.ArrayList; import java.ut

Codeforces 396B On Sum of Fractions 规律题

题目链接:点击打开链接 我们把 1 / { u(i)*v(i) }拆开->  (1/(u(i)-v(i)) * ( 1/v(i) - 1/u(i) ) 若n +1  是素数,则显然(1/(u(i)-v(i)) * ( 1/v(i) - 1/u(i) ) 这样完全相同的式子有 u(i)-v(i) 个 那么就可以把前面系数约掉,那么剩下的式子就是 1/2 - 1/(n+1) 若不是,则我们找到第一个<=n的素数,即v(n) 和第一个>n的素数,即 u(n) 然后前面的 2-v(n)求和,即

Codeforces 48C The Race 模拟题

题目链接:点击打开链接 题意: 给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油. 在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油. 开始有x升油 下面给出加油的记录. 问下一次加油在哪一站.若答案唯一输出具体哪站. 油箱容量无限 思路: 水模拟.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

CodeForces 22D Segments 排序水题

题目链接:点击打开链接 右端点升序,取右端点 暴力删边 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <set> #include <math.h> using namespace std; #define inf 10

数字根(digital root)

来源:LeetCode 258  Add Dights Question:Given a non-negative integer  num , repeatedly add all its digits until the result has only one digit. For example: Given  num = 38 , the process is like:  3 + 8 = 11 ,  1 + 1 = 2 . Since  2  has only one digit, r