标签:mathematics 数学
数学题。
弄懂了之久其实就是解一个一元二次方程 x*(x-1)/2=y 。如果y==0了。表明刚好是这个数。
不是的话,就x取大一位然后 y-n 再%9 。
不过记得 %9==0的时候是9。不会出现0。
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
#define LL long long
using namespace std;
int main()
{
// freopen("in.txt","r",stdin);
// freopen("2.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--)
{
LL n,m;
scanf("%lld",&n);
int x = int((sqrt(1.0 + 8.0*n) -1)/2);
int y = int(n-x*(x+1)/2);
if(y == 0)//刚好是 n*(n+1)/2
{
if(int(x)%9 == 0)
printf("9\n");
else
printf("%d\n", int(x)%9);
}
else//在之间
{
if(y%9 == 0)
printf("9\n");
else
printf("%d\n", y%9);
}
}
}
标签:mathematics 数学
原文地址:http://blog.csdn.net/dongshimou/article/details/37956387