京东求幂那道题

//感觉跟牛妹的思路差不多,不知道为什么就是20%,自己手算了几个都可以
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		//int n = sc.nextInt();
		int n=5;
		long count=0;
		for(int i =1;i<=n;i++) {
			for(int j=1;j<=n;j++) {
				if(i==1) {
					count=(count+n*n)%1000000007;
					break;
				} 
				if(j==1) count=(count+1)%1000000007;
				else {
					int m=getNum(i,j,n);//获取一共可以转化成几个底比自己大的幂
					count=(count+1+2*m)%1000000007;
				}
			}
		}
		System.out.println(count);
	}
	public static int getNum(int a,int b,int n) {
		int m=0;
		if(Math.pow(a,b)<=n) m++;
		//ArrayList<Integer> list = new ArrayList<>();
		//int p=0;
		for(int i=2;i<=b/2;i++) {
			if(b%i==0 && Math.pow(a, i)<=n) m++;
		}
		return m;
		
	}

}

#京东#
全部评论
时间复杂度
点赞 回复 分享
发布于 2017-09-08 21:42
package jindong; import java.util.Scanner; public class Demo2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int n = in.nextInt(); //a b c d互不相同的情况 有多少种 long count = 0; w :for (int i = 2; i <= n; i++) { int t = 0; for (int j = 2; j <= n; j++) { if (Math.pow(j, i) <= n) t++; else { count += (n / i) * t * 2; break w; } } } //加上 a和c都为1 和 a和c都不为1且a和c相等 b和d相等 两种情况 count += n * n + (n - 1) * n; System.out.println(count % 1000000007); } } } 看看我的  交卷后 才写出来的 应该能AC
点赞 回复 分享
发布于 2017-09-08 22:41

相关推荐

码农索隆:我头回见校招简历把个人优势写在最前面的,是我老了吗
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务